コード例 #1
0
        public virtual GameObject GetChildByName(GameObject parent_, string name_, bool isRecursive = false)
        {
            GameObject go = GameObjUtil.FindChild(parent_, name_, isRecursive);

            if (go == null)
            {
                Log.Warn("找不到子对象:" + name_, this);
            }
            return(go);
        }
コード例 #2
0
        /// <summary>
        /// 为子对象添加组件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="go"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public static T AddChildComponent <T>(GameObject go, string path) where T : Component
        {
            GameObject child = GameObjUtil.FindChild(go, path);

            if (child == null)
            {
                Debug.LogWarning(string.Format("miss child: {0}, {1}", go, path));
                return(null);
            }
            return(child.AddComponent <T>());
        }
コード例 #3
0
ファイル: GameObjUtil.cs プロジェクト: vinhphu3000/mg01
        //-------∽-★-∽------∽-★-∽--------∽-★-∽CreateChild∽-★-∽--------∽-★-∽------∽-★-∽--------//

        static public GameObject CreateChildByName(GameObject parent_, string name_)
        {
            GameObject go = GameObjUtil.FindChild(parent_, name_);

            if (go == null)
            {
                //还没创建
                go = GameObjUtil.CreateGameobj(name_);
                GameObjUtil.ChangeParent(go, parent_);
            }

            return(go);
        }
コード例 #4
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽ChildComponent∽-★-∽--------∽-★-∽------∽-★-∽--------//

        /// <summary>
        /// 获取子对象的组件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="go_"></param>
        /// <param name="path_"></param>
        /// <returns></returns>
        public static T GetChildComponent <T>(GameObject go_, string path_) where T : Component
        {
            GameObject child = GameObjUtil.FindChild(go_, path_);

            if (child == null)
            {
                Debug.LogWarning(string.Format("miss child: {0}, {1}", go_, path_));
                return(null);
            }

            T component = child.GetComponent <T>();

            return(component);
        }
コード例 #5
0
ファイル: GameObjUtil.cs プロジェクト: vinhphu3000/mg01
        static public T CreateChildByName <T>(GameObject parent_, string name_) where T : Component
        {
            GameObject go = GameObjUtil.FindChild(parent_, name_);

            if (go == null)
            {
                //还没创建
                go = GameObjUtil.CreateGameobj(name_);
                GameObjUtil.ChangeParent(go, parent_);
            }

            T cmpt = ComponentUtil.EnsureComponent <T>(go);

            return(cmpt);
        }