Beispiel #1
0
        public static UnityEngine.Object GetChildByName(GameObject parent, string name)
        {
            UnityEngine.Object ret = null;

            ForEachChildFunction temp = (UnityEngine.Object obj) =>
            {
                bool compareResult = obj.name.Equals(name);
                ret = compareResult ? obj : null;
                return(compareResult);
            };

            ForEachChild(parent, temp);
            return(ret);
        }
Beispiel #2
0
        public static bool ForEachChild(GameObject obj, ForEachChildFunction fun)
        {
            //广度优先
            Transform root = obj.transform;

            for (int i = 0; i < root.childCount; ++i)
            {
                GameObject kid = root.GetChild(i).gameObject;
                if (true == fun(kid))
                {
                    return(true);
                }
            }

            for (int i = 0; i < root.childCount; ++i)
            {
                GameObject kid = root.GetChild(i).gameObject;
                if (true == ForEachChild(kid, fun))
                {
                    return(true);
                }
            }
            return(false);
        }