Unity3D:UGUI遍歷子控件


參考文章:http://blog.csdn.net/u011185231/article/details/49591383

todo:active和enable的差別?

核心API:

Component.GetComponentInChildren<Transform>(),應該是遞歸獲取所有的child,激活的

GetComponentsInChildren<Transform>(true),激活和未激活的都get

思路:獲取Transform,然后在獲取上面的GameObject。然后對child進行操作。

		//img_bottomPanel_loading是Image
		//GetComponentInChildren獲取第一個child
		Transform firstChild = img_bottomPanel_loading.GetComponentInChildren<Transform> ();
		string name = firstChild.gameObject.name;
		Debug.Log ("firstChild:" + name);

		//獲取所有的children,
		Transform[] children = img_bottomPanel_loading.GetComponentsInChildren<Transform> ();
		for (int i = 0; i < children.Length; i++) {
			string nameTemp = children [i].gameObject.name;
			children [i].gameObject.SetActive (false); //hide
			Debug.Log ("nameTemp:" + nameTemp);
		}
	

 

	private void setBottomOperatePanelHide(bool hide){
		img_bottomPanel_operate.enabled = !hide;
		Transform[] children = img_bottomPanel_operate.GetComponentsInChildren<Transform> (true);
		foreach(Transform tr in children){
			tr.gameObject.SetActive (hide);
		}
	}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM