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


C# Canvas.GetComponentsInChildren方法代码示例

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


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

示例1: initUI

    private void initUI()
    {
        //UI Initializations - Grab Canvas with find object, then grab children for efficiency
        gameUI = FindObjectOfType<Canvas>();

        //get all child sliders
        Component[] canvasSliders = gameUI.GetComponentsInChildren<Slider> ();
        //get all text sliders
        Component[] canvasTexts = gameUI.GetComponentsInChildren<Text> ();

        //loop through and find specific slider
        foreach (Slider child in canvasSliders) {
            if (child.tag.Equals("Enemy HP")) {
                enemyHealth = child;
            }
        }

        //loop through and find specific text
        foreach (Text child in canvasTexts) {
            if (child.tag.Equals("Enemy Ratio")) {
                enemyRatio = child;
            }
        }

        //create listener to run delegate function for updating text ratio of enemy
        enemyHealth.onValueChanged.AddListener (updateEnemyRatio);
    }
开发者ID:Edj3,项目名称:Unity_3PShooter,代码行数:27,代码来源:FireGun.cs

示例2: Start

    // Use this for initialization
    void Start()
    {
        SetSound();

        Image[] images = GetComponentsInChildren<Image>();
        foreach (Image i in images)
            if (i.name == "SoundButton")
            {
                _soundImage = i;
                _soundImage.sprite = (sound == 1) ? soundOnImage : soundOffImage;
            }

        _startMenuCanvas = GetComponentInChildren<Canvas>();
        _startMenuCanvas.enabled = true;

        try {
            _highScoreCanvas = GameObject.Find("HighScoreUI").GetComponentInChildren<Canvas>();
            if (_highScoreCanvas != null)
            {
                _highScoreCanvas.enabled = false;
                SetFontSize(_startMenuCanvas);
            }
        }
        catch(Exception e) { Debug.Log(e);  }

        Text[] textArry = _startMenuCanvas.GetComponentsInChildren<Text>();
        foreach (Text ctext in textArry)
        {
            if (ctext.name.Contains("Score")) ctext.text = "" + Score.getScore();
        }
    }
开发者ID:ShinWonYoung,项目名称:HGU-SE-15,代码行数:32,代码来源:MenuManager.cs

示例3: Start

    // Use this for initialization
    void Start()
    {
        _highScoreCanvas = GetComponentInChildren<Canvas>();
        PlayerNameInputText = _highScoreCanvas.GetComponentInChildren<InputField>();
        if(PlayerNameInputText != null)
        {
            Text[] inputTexts = PlayerNameInputText.gameObject.GetComponentsInChildren<Text>();
            foreach(Text t in inputTexts)
            {
                if (t.name == "Placeholder") t.text = UsersData.DEFAULT_NAME;
            }
        }

        Text[] texts = _highScoreCanvas.GetComponentsInChildren<Text>();
        foreach(Text t in texts)
        {
            t.fontSize = (int)(t.fontSize * ((Screen.width) / 1236f));

            if (t.name.Contains("Player Name")) RankPlayerNameText = t;
            else if(t.name.Contains("Scores")) RankScoreText = t;
        }

        obj_localHighScore = LocalHighScore.getInstance();
        obj_localHighScore.setMaxUser(maxNumOfUsers);
        minScore = obj_localHighScore.getMinScore();

        LoadScores();
    }
开发者ID:ShinWonYoung,项目名称:HGU-SE-15,代码行数:29,代码来源:HighScoreManager.cs

示例4: ToggleButtons

    private void ToggleButtons(Canvas canvas)
    {
        Button[] buttons = canvas.GetComponentsInChildren<Button>();

        for (int i = 0; i < buttons.Length; i++)
            buttons[i].interactable = !buttons[i].interactable;
    }
开发者ID:NicolaiCroutonalAil,项目名称:PTUT-Client_Unity,代码行数:7,代码来源:NavigationScript.cs

示例5: SetFontSize

 public void SetFontSize(Canvas c)
 {
     Text[] texts = c.GetComponentsInChildren<Text>();
     foreach (Text t in texts)
     {
         t.fontSize = (int) (t.fontSize * ((Screen.width) / 1236f));
     }
 }
开发者ID:ShinWonYoung,项目名称:HGU-SE-15,代码行数:8,代码来源:UIBaseClass.cs

示例6: Start

    void Start()
    {
        BackgroundSelection = GetComponent<Canvas>();

        for (int i=0;i<3;i++) {
            ChoiceDisplay[i]=BackgroundSelection.GetComponentsInChildren<GridLayoutGroup>()[i];
        }

        BackgroundSelection.enabled = false;
    }
开发者ID:Rgallouet,项目名称:Blue-Star,代码行数:10,代码来源:BackgroundSelectionButtons.cs

示例7: Awake

 void Awake()
 {
     canvas = gameObject.GetComponent<Canvas> ();
     Text[] texts = canvas.GetComponentsInChildren<Text>();
     foreach (Text t in texts) {
         if(t.name == "scoreValue")
         {
             textScore = t;
         }else if(t.name == "topScoreValue")
         {
             textMaxScore = t;
         }
     }
 }
开发者ID:yizhengtutu,项目名称:snakeX,代码行数:14,代码来源:Score.cs

示例8: Start

    void Start()
    {
        SetSound();
        _isPaused = false;
        _pauseMenuCanvas = GetComponentInChildren<Canvas>();
        _pauseMenuCanvas.enabled = false;

        SetFontSize(_pauseMenuCanvas);

        _confirmTab.SetActive(false);
        Text[] textArry = _pauseMenuCanvas.GetComponentsInChildren<Text>();
        foreach(Text text in textArry) {
            if (text.name.Contains("Score")) _scoreText = text;
        }
    }
开发者ID:ShinWonYoung,项目名称:HGU-SE-15,代码行数:15,代码来源:GameStateManager.cs

示例9: Start

    void Start()
    {
        canvas = GetComponent<Canvas>();
        player=GameObject.FindWithTag ("Player");
        buttons = canvas.GetComponentsInChildren<Button>();
        Alert=GameObject.FindWithTag ("PlugAbility");
        Alert.GetComponent<Text> ().text = "";

        if (buttons != null) {
            buttons [0].onClick.AddListener (() => {
                CoolDownReduction ();});
            buttons [1].onClick.AddListener (() => {
                InvisibleDurationUP ();});
            buttons [2].onClick.AddListener (() => {
                TrulyInvisible ();});

        }
    }
开发者ID:LamentedHarp44,项目名称:Night_Owls_GriffinTGT,代码行数:18,代码来源:PlugMenuScript.cs

示例10: Start

    void Start()
    {
        startMaterial = GetComponent<Renderer> ().material;
        canvas = Instantiate (canvasPrefab, canvasPrefab.transform.position, canvasPrefab.transform.rotation) as Canvas;

        for(int i = 0; i < canvas.GetComponentsInChildren<Text>().Length; i++) {
            if(canvas.GetComponentsInChildren<Text>()[i].tag == "Title") {
                titleText = canvas.GetComponentsInChildren<Text>()[i];
                titleText.text = title;
            }

            if(canvas.GetComponentsInChildren<Text>()[i].tag == "Desc") {
                descText = canvas.GetComponentsInChildren<Text>()[i];
                descText.text = information;
            }

            if(canvas.GetComponentsInChildren<Image>()[i].tag == "Sep") {
                seperatorRect = canvas.GetComponentsInChildren<Image>()[i];
            }
        }

        DisableText ();
    }
开发者ID:VZout,项目名称:Team6Challange,代码行数:23,代码来源:ButtonHoverScript.cs

示例11: Awake

    void Awake()
    {
        StatAllocationMenu = GetComponent<Canvas>();

        for (int i=0; i<6; i++)		{ PrimaryNumbers [i] = 		StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [5].GetComponentsInChildren<Text> () [i+1];}
        for (int i=6; i<12; i++)	{ PrimaryNumbers [i] = 		StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [5].GetComponentsInChildren<Text> () [i+2];}
        for (int i=12; i<14; i++)	{ PrimaryNumbers [i] = 		StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [5].GetComponentsInChildren<Text> () [i+3];}
        for (int i=0; i<2; i++) 	{ HeroicNumbers [i] = 		StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [5].GetComponentsInChildren<Text> () [i+14+4];}
        for (int i=0; i<6; i++) 	{ SecondaryNumbers [i] = 	StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [5].GetComponentsInChildren<Text> () [i+16+5];}
        for (int i=0; i<3; i++) 	{ PointsToAlloc [i] = 		StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [5].GetComponentsInChildren<Text> () [i+28];}

        for (int i=0; i<6; i++)		{ PrimaryPlus [i] = 		StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [6].GetComponentsInChildren<Button> () [i];}
        for (int i=6; i<12; i++)	{ PrimaryPlus [i] = 		StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [7].GetComponentsInChildren<Button> () [i-6];}
        for (int i=12; i<14; i++)	{ PrimaryPlus [i] = 		StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [8].GetComponentsInChildren<Button> () [i-12];}
        for (int i=0; i<2; i++) 	{ HeroicPlus [i] = 			StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [9].GetComponentsInChildren<Button> () [i];}
        for (int i=0; i<6; i++) 	{ SecondaryPlus [i] = 		StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [10].GetComponentsInChildren<Button> ()[i];}

        for (int i=0; i<6; i++)		{ PrimaryMinus [i] = 		StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [0].GetComponentsInChildren<Button> () [i];}
        for (int i=6; i<12; i++)	{ PrimaryMinus [i] = 		StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [1].GetComponentsInChildren<Button> () [i-6];}
        for (int i=12; i<14; i++)	{ PrimaryMinus [i] = 		StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [2].GetComponentsInChildren<Button> () [i-12];}
        for (int i=0; i<2; i++) 	{ HeroicMinus [i] = 		StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [3].GetComponentsInChildren<Button> () [i];}
        for (int i=0; i<6; i++) 	{ SecondaryMinus [i] = 		StatAllocationMenu.GetComponentsInChildren<GridLayoutGroup> () [4].GetComponentsInChildren<Button> () [i];}

        DescriptionHead = GameObject.FindGameObjectWithTag("LoreDisplayHead").GetComponentInChildren<Text> ();
        DescriptionBody = GameObject.FindGameObjectWithTag("LoreDisplayComment").GetComponentInChildren<Text> ();

        StatAllocationMenu.enabled = false;
    }
开发者ID:Rgallouet,项目名称:Blue-Star,代码行数:28,代码来源:StatAllocationButtons.cs

示例12: Start

 void Start()
 {
     canvas = GameObject.Find("Canvas").GetComponent<Canvas>();
     dialog = canvas.GetComponentsInChildren<Text> ()[0];
 }
开发者ID:zbotman12,项目名称:LudumDare33,代码行数:5,代码来源:TalkScript.cs

示例13: openShopWindow

    /*
     * This method opens the shop window from the shopUI Prefab (set in the inspector).
     * It then sets all the visual components up, assigns them to variables and updates the shop.
     */
    private void openShopWindow()
    {
        _player.GetComponent<PlayerController>().ignoreInput = true; // While the menu is open, ignore the player's movement
        _shopUI = Object.Instantiate(shopUIPrefab) as Canvas;

        _dropdown = _shopUI.GetComponentInChildren<Dropdown>();
        // Add a listener to update the current item info when a new item is selected from the dropdown item list
        _dropdown.onValueChanged.AddListener((int i) => {
            this.updateCurrentItemInfo();
        });

        // Access the Text elements of the shop UI and make them blank for now
        foreach(Text t in _shopUI.GetComponentsInChildren<Text>()){
            if(t.name == "Quantity"){
                _quantity = t;
                _quantity.text = "";
            }
            else if(t.name == "Price"){
                _price = t;
                _price.text = "";
            }
        }

        _slider = _shopUI.GetComponentInChildren<Slider>();
        // We add a listener to the quantity slider
        // When the amount of item requested is changed, the quantity text and total price update
        _slider.onValueChanged.AddListener((float f) => {
            if(_dropdown.value != 0){
                _quantity.text = _slider.value + "";
                _price.text = "$ " +((int)_slider.value) * _prices[_dropdownIDs[_dropdown.value]]; //Total price = Quantity * price of current item
            }
        });
        _slider.gameObject.SetActive(false); // Hide the slider until we select an item from the dropdown

        Button[] buttons = _shopUI.GetComponentsInChildren<Button>();
        buttons[0].onClick.AddListener(() => { // Set the "<Back" button to close the shop
            this.closeShopWindow();
        });
        buttons[1].onClick.AddListener (() =>{ // Set the "Buy" button to attempt to purchase the chosen quantity of the chosen item
            this.buy();
        });
        updateDropdownList();
    }
开发者ID:ryanjk,项目名称:PinkPlatypus,代码行数:47,代码来源:ShopMain.cs


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