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);
		}
	}

  

转载于:https://www.cnblogs.com/makebetter/p/6704115.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值