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