Esempio n. 1
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽gameobject管理∽-★-∽--------∽-★-∽------∽-★-∽--------//

        public GameObject CreateGo(string url_, CALLBACK_GO onComplete_)
        {
            url_ = url_.ToLower();

            GameObject prefab = m_assetCache.GetAsset(url_) as GameObject;

            if (prefab == null)
            {
                Log.Assert("gameobject未加载:" + url_);
                return(null);
            }

            GameObject go = GameObjUtil.CreateGameObj(prefab);

            GameObjUtil.DontDestroyOnLoad(go);  //所有加载出来的go都是默认不销毁

            AddGo(url_, go);

            if (onComplete_ != null)
            {
                onComplete_(go);
            }

            return(go);
        }
Esempio n. 2
0
 /// <summary>
 /// 显示默认go, 子类重写
 /// </summary>
 virtual protected void ShowGameObject()
 {
     if (m_gameObject == null)
     {
         //如果没有, 则创建一个空容器
         ShowGameObject(GameObjUtil.CreateGameobj(TypeName), false);
     }
 }
Esempio n. 3
0
 //public bool ignoreRestart = false;
 void Awake()
 {
     //if (!ignoreRestart)
     //{
     //    ResMgr.AddImmortalObject(gameObject);
     //}
     GameObjUtil.DontDestroyOnLoad(gameObject);
     Destroy(this);
 }
Esempio n. 4
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽Transform∽-★-∽--------∽-★-∽------∽-★-∽--------//


        //移出父级
        virtual protected void RemoveChildThis()
        {
            if (m_goIsExternal)
            {
                //外部go,不负责移除
                return;
            }

            GameObjUtil.RemoveFromParent(this.gameObject);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        /// <summary>
        /// 销毁垃圾桶里的子对象
        /// </summary>
        /// <param name="child_"></param>
        /// <returns></returns>
        public bool Delete(GameObject child_)
        {
            if (!Contains(child_))
            {
                return(false);
            }

            m_objArr.Remove(child_);
            GameObjUtil.Delete(child_);
            return(true);
        }
Esempio n. 7
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>());
        }
Esempio n. 8
0
        public GameObject Pop(GameObject child_, GameObject toParent_)
        {
            if (!Contains(child_))
            {
                return(null);
            }

            m_objArr.Remove(child_);

            GameObjUtil.ChangeParent(child_, toParent_);
            return(child_);
        }
Esempio n. 9
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽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);
        }
Esempio n. 10
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽数据操作∽-★-∽--------∽-★-∽------∽-★-∽--------//

        /// <summary>
        /// 回收对象
        /// </summary>
        /// <param name="obj_"></param>
        public void Push(GameObject child_)
        {
            if (Contains(child_))
            {
                return;
            }

            GameObjUtil.RecordLocalMatrix(child_.transform);  //记录位置
            child_.transform.parent = m_transform;
            GameObjUtil.ApplyLocalMatrix(child_.transform);   //恢复位置

            m_objArr.Add(child_);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        /// <summary>
        /// 替换子对象
        /// </summary>
        /// <param name="name_"></param>
        /// <param name="replace_"></param>
        public void ReplaceChildByName(string name_, GameObject replace_)
        {
            GameObject child = GetChildByName(name_, true);

            if (child == null)
            {
                return;
            }

            GameObject parent = GameObjUtil.GetParent(child);

            GameObjUtil.RecordLocalMatrix(child.transform);
            GameObjUtil.ApplyLocalMatrix(replace_.transform);

            GameObjUtil.Delete(child);  //删除原来的子对象
            GameObjUtil.ChangeParent(replace_, parent);
        }
Esempio n. 14
0
        //初始化容器
        protected void InitGameObject(string name_)
        {
            if (m_gameObject)
            {
                return;
            }

            string name = string.IsNullOrEmpty(name_) ? this.GetType().Name : name_;    //容器名称

            m_gameObject          = GameObjUtil.CreateGameobj(name);
            m_gameObject.isStatic = true;   //设置为静态对象
            m_transform           = m_gameObject.transform;

            GameObjUtil.DontDestroyOnLoad(m_gameObject);

            AllocPoolPos(m_gameObject);
        }
Esempio n. 15
0
        /// <summary>
        /// 清空所有子对象
        /// 仅清除对象列表
        /// </summary>
        public void Clear()
        {
            if (m_objArr.Count == 0)
            {
                return;
            }

            GameObject go;
            var        enumerator = m_objArr.GetEnumerator();

            while (enumerator.MoveNext())
            {
                go = enumerator.Current;
                GameObjUtil.Delete(go); //直接销毁,会不会导致其他引用者产生空对象?
            }
            enumerator.Dispose();

            m_objArr.Clear();
        }
Esempio n. 16
0
        protected override void __Dispose(bool disposing_)
        {
            Clear();

            if (disposing_)
            {
                if (m_gameObject != null)
                {
                    GameObjUtil.Delete(m_gameObject);
                    m_gameObject = null;
                }
            }
            else
            {
                if (m_gameObject != null)
                {
                    Log.Fatal("gameObject销毁失败", this.GetType());
                }
            }
        }
Esempio n. 17
0
        protected void ClearGameObject()
        {
            if (m_gameObject == null)
            {
                return;
            }

            __ClearGameObject();

            if (m_goIsExternal)
            {
                //如果是外部go, 只是移除引用
                m_gameObject = null;
            }
            else
            {
                //是自己托管的go, 则删除对象
                GameObjUtil.Delete(m_gameObject);
                //GameObjUtil.DestroyNow(m_gameObject);
                m_gameObject = null;
            }
        }
Esempio n. 18
0
        static void __Setup()
        {
            m_appBhv = ComponentUtil.EnsureComponent <CCAppBhv>(m_gRoot);

            if (!m_trash)
            {
                m_trash = GameObjUtil.CreateGameobj("Trash");
                GameObjUtil.DontDestroyOnLoad(m_trash);
                m_trash.transform.position = new Vector3(-1000, -1000, -1000);
                m_trash.isStatic           = true; //设置为静态对象
            }


            m_resMgr = m_resMgr ?? new ResMgr();
            m_resMgr.Setup();

            m_soundMgr = m_soundMgr ?? new SoundMgr(m_gRoot);
            m_soundMgr.Setup();

            m_keyboard.Setup();

            m_classPools = ClassPools.me;

            //
            TimerMgr.inst.Setup();
            //
            ActionMgr.inst.Setup();
            //
            UserPrefs.Setup();

            if (CCDefine.DEBUG)
            {
                //显示帧频
                ComponentUtil.EnsureComponent <FpsTicker>(m_gRoot);
            }


            LogFile.Run();
        }
Esempio n. 19
0
        static void __Clear()
        {
            m_keyboard.Clear();

            m_subject.DetachAll();

            m_autoRelease.Excute();

            m_resMgr.Clear();
            m_soundMgr.Clear();

            //对象池清除
            m_classPools.Clear();
            m_classPools = null;

            //单例清除
            TimerMgr.inst.Clear();
            ActionMgr.inst.Clear();

            UserPrefs.Clear();
            Refer.ClearNotify();


            GameObject.Destroy(m_appBhv);
            m_appBhv = null;

            m_gRoot = null;

            m_onLateUpdate = null;
            m_onUpdate     = null;
            m_onGui        = null;

            if (m_trash)
            {
                m_trash = GameObjUtil.Delete(m_trash);
            }
        }