Unity遍历子结点
2016-07-26
遍历子结点,使用
1 2 3 4 |
//子结点数量 go.transform.childCount //子结点 go.transform.GetChild(i) |
例子备忘
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
//遍历结点 private static void DoAddPlaySound(GameObject go, StreamWriter upsw) { UIButton btn = go.GetComponent<UIButton>(); JPlaySound sound = go.GetComponent<JPlaySound>(); if (null == sound && null != btn) { //添加Sound JPlaySound sd = go.AddComponent<JPlaySound>(); sd.audioType = NormalAudioType.UIBtnEnsure; } for (int i = 0; i < go.transform.childCount; ++i) { Transform trans = go.transform.GetChild(i); GameObject goChild = trans.gameObject; DoAddPlaySound(goChild, upsw); } } |