參考文章: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); } }