当前位置: 首页>>代码示例>>C#>>正文


C# WorldObject.GetComponent方法代码示例

本文整理汇总了C#中WorldObject.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# WorldObject.GetComponent方法的具体用法?C# WorldObject.GetComponent怎么用?C# WorldObject.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WorldObject的用法示例。


在下文中一共展示了WorldObject.GetComponent方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetUpBlip

 public void SetUpBlip(Sprite mapIcon, Color teamColor, int ID, WorldObject target, Minimap map)
 {
     /*		if (teamColor == null) {
         teamColor = new Color(0,0,0,255);
     }*/
     if (!sprite) sprite = GetComponent<Image>();
     Map = map;
     Target = target._transform;
     ownersID = "ID" + ID.ToString();
     MapIcon = mapIcon;
     sprite.sprite = MapIcon;
     TeamColor = new Color(teamColor.r, teamColor.g, teamColor.b, 1);
     sprite.color = TeamColor;
     Unit unit = target.GetComponent<Unit>();
     if (unit) {
         if (unit.unitType == UnitType.Hero)
             KeepInBounds = true;
     }
     SetUp = true;
 }
开发者ID:sentonnes,项目名称:RTS-Framework,代码行数:20,代码来源:Blip.cs

示例2: OnGUI

    void OnGUI()
    {
        if (Input.GetMouseButtonDown(0))
        {
            timeLeftBeforeDeclarateDrag = 0.2f;
            mousePosition1 = Input.mousePosition;
        }
        else if (Input.GetMouseButton(0))
        {
            if (!isSelecting)
            {
                timeLeftBeforeDeclarateDrag -= Time.deltaTime;
                isSelecting = (timeLeftBeforeDeclarateDrag <= 0f);
            }

            if (isSelecting)
            {
                mousePosition2 = Input.mousePosition;
                Rect rect = GetScreenRect(mousePosition1, mousePosition2);
                GUI.DrawTexture(rect, DragBoxSelection);
                DrawScreenRectBorder(rect, 2, DragBoxSelectionBorder);
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            isSelecting = false;
            timeLeftBeforeDeclarateDrag = 0f;
        }

        GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(Screen.width / 1920f, Screen.height / 1080f, 1f));

        if (player && player.human)
        {
            string selectionName = "", hitText = "";

            transform.FindChild("ResourceBar").FindChild("TextNelther").GetComponent<Text>().text = resourceValues[ResourceType.Nelther].ToString();
            transform.FindChild("ResourceBar").FindChild("TextGold").GetComponent<Text>().text = resourceValues[ResourceType.Gold].ToString();
            transform.FindChild("ResourceBar").FindChild("TextElynium").GetComponent<Text>().text = resourceValues[ResourceType.Elynium].ToString();
            transform.FindChild("ResourceBar").FindChild("TextPopulation").GetComponent<Text>().text = resourceValues[ResourceType.Population].ToString() + "/" + resourceLimits[ResourceType.Population].ToString();

            if (player.SelectedObject.Count > 0 && player.IsOwnedBy(player))
            {
                if (lastSelection && lastSelection != player.SelectedObject[0])
                {
                    transform.FindChild("Frame1").FindChild("Frame").gameObject.SetActive(false);
                    transform.FindChild("Frame1").FindChild("UnitNameProduct").gameObject.SetActive(false);
                    for(int j = 1; j < 6; j++)
                    {
                        transform.FindChild("Frame1").FindChild("FrameUnit" + j.ToString()).gameObject.SetActive(false);
                    }
                    for (int i = 1; i < 16; i++)
                    {
                        transform.FindChild("ActionBar").FindChild("OrderBar").FindChild("Button" + i.ToString()).GetComponent<Image>().sprite = buttonSprite;
                    }
                }

                DrawActions(player.GetActions());

                lastSelection = player.SelectedObject[0];
                Building selectedBuilding = lastSelection.GetComponent<Building>();
                if (selectedBuilding)
                {
                    DrawBuildQueue(selectedBuilding.getBuildQueueValues(), selectedBuilding.getBuildPercentage());
                }
            }
            else
            {
                transform.FindChild("Frame1").FindChild("Frame").gameObject.SetActive(false);
                transform.FindChild("Frame1").FindChild("UnitNameProduct").gameObject.SetActive(false);
                for (int j = 1; j < 6; j++)
                {
                    transform.FindChild("Frame1").FindChild("FrameUnit" + j.ToString()).gameObject.SetActive(false);
                }
                for (int i = 1; i < 16; i++)
                {
                    transform.FindChild("ActionBar").FindChild("OrderBar").FindChild("Button" + i.ToString()).GetComponent<Image>().sprite = buttonSprite;
                }
            }

            if (player.SelectedObject.Count > 0)
            {
                transform.FindChild("Frame1").FindChild("Object").gameObject.SetActive(true);

                transform.FindChild("Frame1").FindChild("Object").gameObject.GetComponent<Image>().sprite = player.SelectedObject[0].buildImage;
                selectionName = player.SelectedObject[0].objectName;
                hitText = player.SelectedObject[0].hitPoints.ToString() + " / " + player.SelectedObject[0].maxHitPoints.ToString();
            }
            else
                transform.FindChild("Frame1").FindChild("Object").gameObject.SetActive(false);

            transform.FindChild("Frame1").FindChild("Text").GetComponent<Text>().text = selectionName;
            transform.FindChild("Frame1").FindChild("HitText").GetComponent<Text>().text = hitText;

            DrawMouseCursor();
        }
    }
开发者ID:Phelisse,项目名称:Elynium,代码行数:96,代码来源:HUD.cs

示例3: ChangeSelection

 private void ChangeSelection(WorldObject worldObject, Player controller)
 {
         //cela devrait être appelé par la ligne suivante, mais il y a une petite chance qu'il ne sera pas
         if ((!Input.GetKey(KeyCode.LeftShift) || worldObject.GetComponent<Resource>() || !worldObject.IsOwnedBy(player)))
         {
             SetSelection(false, playingArea);
             if (controller.SelectedObject.Count > 0)
             {
                 foreach (WorldObject wo in new ArrayList(controller.SelectedObject))
                 {
                     wo.SetSelection(false, playingArea);
                 }
             }
             controller.SelectedObject.Clear();
         }
         controller.SelectedObject.Add(worldObject);
         worldObject.SetSelection(true, controller.hud.GetPlayingArea());
 }
开发者ID:Phelisse,项目名称:Elynium,代码行数:18,代码来源:WorldObject.cs

示例4: DrawOrdersBar

	private void DrawOrdersBar() {
    	GUI.skin = ordersSkin;
        GUI.BeginGroup(new Rect(
            Screen.width - ResourceManager.ORDERS_BAR_WIDTH - BUILD_IMAGE_WIDTH, 
            ResourceManager.RESOURCE_BAR_HEIGHT, 
            ResourceManager.ORDERS_BAR_WIDTH + BUILD_IMAGE_WIDTH, 
            Screen.height - ResourceManager.RESOURCE_BAR_HEIGHT));
        GUI.Box(new Rect(BUILD_IMAGE_WIDTH + SCROLL_BAR_WIDTH, 0, ResourceManager.ORDERS_BAR_WIDTH, Screen.height - ResourceManager.RESOURCE_BAR_HEIGHT),"");


    	// Display the object selected, if there is only one object selected
    	string selectionName = "";
		if (player.selections.Count == 1) {
            WorldObject selectedObject = player.selections[0];
    		selectionName = player.selections[0].objectName;

            if (selectedObject.IsOwnedBy(player) ) {
                // reset slider value if the selected object has changed
                if (lastSelection && lastSelection != selectedObject) sliderValue = 0.0f;
                
                // Draw the list of actions 
                DrawActions(selectedObject.GetActions());
                
                // store the current selection
                lastSelection = selectedObject;

                Building selectedBuilding = lastSelection.GetComponent< Building >();
                if (selectedBuilding) {
                    DrawBuildQueue(selectedBuilding.getBuildQueueValues(), selectedBuilding.getBuildPercentage());
                    DrawStandardBuildingOptions(selectedBuilding);
                }
            }
		}

        if (!selectionName.Equals("")) {
            float leftPos = BUILD_IMAGE_WIDTH + SCROLL_BAR_WIDTH / 2;
            float topPos = buildAreaHeight + BUTTON_SPACING;
            GUI.Label(new Rect(leftPos, topPos, ResourceManager.ORDERS_BAR_WIDTH, SELECTION_NAME_HEIGHT), selectionName);
        }

    	GUI.EndGroup();
	}
开发者ID:MaximeKestemont,项目名称:RTS_game,代码行数:42,代码来源:HUD.cs

示例5: DrawOrdersBar

 private void DrawOrdersBar()
 {
     GUI.skin = ordersSkin;
     GUI.BeginGroup(new Rect(Screen.width-ORDERS_BAR_WIDTH-BUILD_IMAGE_WIDTH,RESOURCE_BAR_HEIGHT,ORDERS_BAR_WIDTH+BUILD_IMAGE_WIDTH,Screen.height-RESOURCE_BAR_HEIGHT));
     GUI.Box(new Rect(BUILD_IMAGE_WIDTH+SCROLL_BAR_WIDTH,0,ORDERS_BAR_WIDTH,Screen.height-RESOURCE_BAR_HEIGHT),"");
     string selectionName = "";
     if(player.SelectedObject) {
         selectionName = player.SelectedObject.objectName;
         if(player.SelectedObject.IsOwnedBy(player)){
             //reset slider value if the selected object has changed
             if(lastSelection && lastSelection != player.SelectedObject) sliderValue = 0.0f;
             DrawActions(player.SelectedObject.GetActions());
             //store the current selection
             lastSelection = player.SelectedObject;
             Building selectedBuilding = lastSelection.GetComponent<Building>();
             if(selectedBuilding) {
                 DrawBuildQueue(selectedBuilding.getBuildQueueValues(), selectedBuilding.getBuildPercentage());
                 DrawStandardBuildingOptions(selectedBuilding);
             }
         }
     }
     if(!selectionName.Equals("")) {
         int leftPos = BUILD_IMAGE_WIDTH + SCROLL_BAR_WIDTH / 2;
         int topPos = buildAreaHeight + BUTTON_SPACING;
         GUI.Label(new Rect(leftPos,topPos,ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), selectionName);
     }
     GUI.EndGroup();
 }
开发者ID:am200,项目名称:game2,代码行数:28,代码来源:HUD.cs

示例6: UpgradeUnit

 private void UpgradeUnit(WorldObject specificUnit, string unitStat, float valueToAdd)
 {
     specificUnit.GetComponent<Unit>().upgradeStat(unitStat, valueToAdd);
 }
开发者ID:sentonnes,项目名称:RTS-Framework,代码行数:4,代码来源:Player.cs

示例7: UpgradeHero

 private void UpgradeHero(WorldObject specificHero, string heroStat, float valueToAdd)
 {
     specificHero.GetComponent<Hero>().upgradeStat(heroStat, valueToAdd);
 }
开发者ID:sentonnes,项目名称:RTS-Framework,代码行数:4,代码来源:Player.cs

示例8: UpgradeBuilding

 private void UpgradeBuilding(WorldObject specificBuilding, string buildingStat, float valueToAdd)
 {
     specificBuilding.GetComponent<Building>().upgradeStat(buildingStat, valueToAdd);
 }
开发者ID:sentonnes,项目名称:RTS-Framework,代码行数:4,代码来源:Player.cs

示例9: DrawOrdersBar

    private void DrawOrdersBar()
    {
        GUI.skin = ordersSkin;
        GUI.BeginGroup(new Rect(Screen.width - ORDERS_BAR_WIDTH - BUILD_IMAGE_WIDTH, RESOURCE_BAR_HEIGHT, ORDERS_BAR_WIDTH + BUILD_IMAGE_WIDTH, Screen.height - RESOURCE_BAR_HEIGHT));
        GUI.Box(new Rect(BUILD_IMAGE_WIDTH + SCROLL_BAR_WIDTH, 0, ORDERS_BAR_WIDTH, Screen.height - RESOURCE_BAR_HEIGHT), "");
        string selectionName = "";

        if(player.SelectedObject) {
            selectionName = player.SelectedObject.objectName;

            if(player.SelectedObject.IsOwnedBy(player)){
                //reset slider value if the selected object has changed
                if(lastSelection && lastSelection != player.SelectedObject)
                    sliderValue = 0.0f;
                DrawActions(player.SelectedObject.GetActions());
                //store the current selection
                lastSelection = player.SelectedObject;
                Building selectedBuilding = lastSelection.GetComponent<Building>();
                if(selectedBuilding) {
                    DrawBuildQueue(selectedBuilding.getBuildQueueValues(), selectedBuilding.getBuildPercentage());
                    DrawStandardBuildingOptions(selectedBuilding);
                }

                Unit selectedUnit = lastSelection.GetComponent<Unit>();
                if(selectedUnit)
                    DrawStandardUnitOptions(selectedUnit);
            }

            if(!selectionName.Equals("")) {
                int leftPos = BUILD_IMAGE_WIDTH + SCROLL_BAR_WIDTH / 2;
                int topPos = 70;
                GUI.Label(new Rect(leftPos, 10, ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), selectionName);
                GUI.Label(new Rect(leftPos, 30, ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), "Level: " + player.SelectedObject.level);
                GUI.Label(new Rect(leftPos, 50, ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), "Life: " + player.SelectedObject.hitPoints + "/" + player.SelectedObject.maxHitPoints);

                if(player.SelectedObject.objectName == "Gold Mine"){
                    GUI.Label(new Rect(leftPos, topPos, ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), "Generated: " + player.SelectedObject.GetComponent<GoldMine>().totalAmount);
                    topPos += 20;
                    GUI.Label(new Rect(leftPos, topPos, ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), "Rate: " + player.SelectedObject.GetComponent<GoldMine>().productionRate);

                }
                if(player.SelectedObject.objectName == "Castle") {
                    GUI.Label(new Rect(leftPos, topPos, ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), "Generated: " + player.SelectedObject.GetComponent<Castle>().totalAmount);
                    topPos += 20;
                    GUI.Label(new Rect(leftPos, topPos, ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), "Rate: " + player.SelectedObject.GetComponent<Castle>().productionRate);

                }
                if(player.SelectedObject.objectName == "Barracks") {
                    if(player.SelectedObject.level >= 1) {
                        GUI.Label(new Rect(leftPos, topPos, ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), "Orc: " + ResourceManager.O);
                        topPos += 20;
                    }
                    if(player.SelectedObject.level >= 2) {
                        GUI.Label(new Rect(leftPos, topPos, ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), "Blue Goblin: " + ResourceManager.B);
                        topPos += 20;
                    }
                    if(player.SelectedObject.level >= 3) {
                        GUI.Label(new Rect(leftPos, topPos, ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), "Skull Warrior: " + ResourceManager.S);
                        topPos += 20;
                    }
                    if(player.SelectedObject.level == 4) {
                        GUI.Label(new Rect(leftPos, topPos, ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), "Demon: " + ResourceManager.D);
                        topPos += 20;
                    }
                }
                if(player.SelectedObject.objectName == "Orc" || player.SelectedObject.objectName == "Blue Goblin" ||
                   player.SelectedObject.objectName == "Skull Warrior" || player.SelectedObject.objectName == "Demon" ) {
                    GUI.Label(new Rect(leftPos, topPos, ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), "Damage: " + player.SelectedObject.GetComponent<Unit>().damage);
                    topPos += 20;
                    GUI.Label(new Rect(leftPos, topPos, ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), "Speed: " + player.SelectedObject.GetComponent<Unit>().moveSpeed);
                    topPos += 20;
                    GUI.Label(new Rect(leftPos, topPos, ORDERS_BAR_WIDTH,SELECTION_NAME_HEIGHT), "Kills: " + player.SelectedObject.GetComponent<Unit>().kills);
                }
                buttonPlacement = topPos + 20;
            }

        }

        GUI.EndGroup();
    }
开发者ID:K-Dasu,项目名称:Senior-Design,代码行数:80,代码来源:HUD.cs

示例10: DrawOrdersBar

    private void DrawOrdersBar()
    {
        GUI.skin = orderSkin;
        GUI.BeginGroup(new Rect(Screen.width - ORDER_BAR_WIDTH, Screen.height-ORDER_BAR_HEIGHT, ORDER_BAR_WIDTH, ORDER_BAR_HEIGHT));
        GUI.Box(new Rect(0, 0, ORDER_BAR_WIDTH, ORDER_BAR_HEIGHT), "");
        if (player.SelectedObject)
        {
            if (player.SelectedObject.IsOwnedBy(player))
            {
                //reset slider value if the selected object has changed
                if (lastSelection && lastSelection != player.SelectedObject) sliderValue = 0.0f;
                DrawActions(player.SelectedObject.GetActions());
                //store the current selection
                lastSelection = player.SelectedObject;
                Building selectedBuilding = lastSelection.GetComponent<Building>();
                if (selectedBuilding)
                {
                    DrawStandardBuildingOptions(selectedBuilding);
                }

            }
        }
        GUI.EndGroup();
    }
开发者ID:matkal-2,项目名称:Unity-Projects,代码行数:24,代码来源:HUD.cs

示例11: DrawOrdersBar

    private void DrawOrdersBar()
    {
        GUI.skin = ordersSkin;
        GUI.BeginGroup(new Rect(Screen.width-ORDERS_BAR_WIDTH,RESOURCE_BAR_HEIGHT,ORDERS_BAR_WIDTH,Screen.height-RESOURCE_BAR_HEIGHT));
        GUI.Box(new Rect(0,0,ORDERS_BAR_WIDTH,Screen.height-RESOURCE_BAR_HEIGHT),"");
        if (this.orderBarState == WorldObjectType.None) {
            GUI.EndGroup();
            return;
        }
        // draw the info
        int row = 0;
        // write the name of the currently selected object
        if(player.SelectedObject) {
            string selectionName = player.SelectedObject.objectName;
            if(selectionName != "") {
                int topPos = buildAreaHeight + BUTTON_SPACING;
                GUI.Label(new Rect(PADDING,row*PADDING,ORDERS_BAR_WIDTH - 2*PADDING,LABEL_HEIGHT), selectionName);
            }
            if(player.SelectedObject.BelongsToPlayer(this.player)) {
                row++;
                GUI.Label(new Rect(PADDING,PADDING + row*LABEL_HEIGHT,ORDERS_BAR_WIDTH - 2*PADDING,LABEL_HEIGHT), "You own this");
                //reset slider value if the selected object has changed
                if(this.lastSelectedObject && this.lastSelectedObject != player.SelectedObject) this.sliderValue = 0.0f;
                DrawActions(player.SelectedObject.GetActions());
                //store the current selection
                this.lastSelectedObject = player.SelectedObject;
                if(this.orderBarState == WorldObjectType.Building) {
                    // draw build status
                    Building selectedBuilding = lastSelectedObject.GetComponent<Building>();
                    if(selectedBuilding) {
                        DrawBuildQueue(selectedBuilding.getBuildQueueValues(), selectedBuilding.getBuildPercentage());
                    }
                } else if(this.orderBarState == WorldObjectType.Unit) {
                    Unit selectedUnit = lastSelectedObject.GetComponent<Unit>();
                    if(selectedUnit) {
                        row++;
                        Texture2D icon = this.healthIcon;
                        string healthString = selectedUnit.currentHealth.ToString() + "/" + selectedUnit.maxHealth.ToString();
                        DrawIconWithText(icon, PADDING, PADDING, PADDING + row*LABEL_HEIGHT, healthString);
                    }
                }
            }
        }

        GUI.EndGroup();
    }
开发者ID:devend711,项目名称:game-tutorial,代码行数:46,代码来源:HUD.cs


注:本文中的WorldObject.GetComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。