Example #1
0
        private static void BackToPool(GameObjectCeil ceil)
        {
            CreatDict(ceil.ThePath);
            if (!ceil.IsBeingUse)
            {
#if UNITY_EDITOR
                Debug.LogError("[资产非法][资产回池异常!!][重复回池][The Asset Name:]" + ceil.ThePath);
                UnityEditor.EditorApplication.isPlaying = false;
#endif
                return;
            }

            ceil.SetBeingUse(false);
            if (null != ceil.TheTransform)
            {
                ceil.TheTransform.parent = m_root;
            }

            if (m_using[ceil.ThePath].Contains(ceil))
            {
                m_using[ceil.ThePath].Remove(ceil);
            }
            if (!m_idle[ceil.ThePath].Contains(ceil))
            {
                m_idle[ceil.ThePath].Add(ceil);
            }
        }
Example #2
0
        public static void AsyncGet(string path, Action <GameObject> cb)
        {
            GameObjectCeil          ceil = GetFromPool(path);
            Action <GameObjectCeil> go   = (obj) =>
            {
                if (obj = null)
                {
                    return;
                }

                CreatDict(path);
                ceil.SetBeingUse(true);
                m_using[path].Add(ceil);

                cb?.Invoke(obj.TheGameobject);
            };

            if (null != ceil)
            {
                go.Invoke(ceil);
            }
            else
            {
                GetFromAysncLoad(path, go);
            }
        }
Example #3
0
 private static void Destroy(GameObjectCeil ceil)
 {
     if (m_using.ContainsKey(ceil.ThePath) && m_using[ceil.ThePath].Contains(ceil))
     {
         m_using[ceil.ThePath].Remove(ceil);
     }
     if (m_idle.ContainsKey(ceil.ThePath) && m_idle[ceil.ThePath].Contains(ceil))
     {
         m_idle[ceil.ThePath].Remove(ceil);
     }
     ResourceLoader.UnloadObject(ceil.ThePath);
 }
Example #4
0
        private static GameObjectCeil GetFromLoad(string path)
        {
            UnityEngine.Object obj = ResourceLoader.LoadObject(path, typeof(GameObject));
            if (null == obj)
            {
                return(null);
            }

            GameObject     target = GameObject.Instantiate(obj) as GameObject;
            GameObjectCeil ceil   = target.AddComponentIfNotExist <GameObjectCeil>();

            ceil.Init(path, Destroy);
            ceil.TheTransform.parent = m_root;
            return(ceil);
        }
Example #5
0
        private static void GetFromAysncLoad(string path, Action <GameObjectCeil> cb)
        {
            ResourceLoader.AsyncLoadObject(path, typeof(GameObject), (obj) =>
            {
                if (null == obj)
                {
                    cb?.Invoke(null);
                    return;
                }

                GameObject target   = GameObject.Instantiate(obj) as GameObject;
                GameObjectCeil ceil = target.AddComponentIfNotExist <GameObjectCeil>();
                ceil.Init(path, Destroy);
                ceil.TheTransform.parent = m_root;
                cb?.Invoke(ceil);
            });
        }
Example #6
0
        public static void Back(GameObject obj)
        {
            if (null == obj)
            {
                return;
            }
            GameObjectCeil ceil = obj.GetComponent <GameObjectCeil>();

            if (null == ceil)
            {
                GameObject.Destroy(obj);
            }
            else
            {
                BackToPool(ceil);
            }
        }
Example #7
0
        private static GameObjectCeil GetFromPool(string path)
        {
            if (!m_idle.ContainsKey(path))
            {
                return(null);
            }

            GameObjectCeil ceil  = null;
            int            index = m_idle[path].Count;

            while (true)
            {
                index--;
                if (index < 0)
                {
                    break;
                }

                ceil = m_idle[path][index];
                m_idle[path].RemoveAt(index);
                if (null != ceil)
                {
                    if (ceil.IsDestroyed)
                    {
#if UNITY_EDITOR
                        Debug.LogError("[资产非法][资产销毁异常!!][The Asset Name:]" + ceil.ThePath);
                        UnityEditor.EditorApplication.isPlaying = false;
#endif
                    }
                    else if (ceil.IsBeingUse)
                    {
#if UNITY_EDITOR
                        Debug.LogError("[资产非法][资产使用异常!!][The Asset Name:]" + ceil.ThePath);
                        UnityEditor.EditorApplication.isPlaying = false;
#endif
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(ceil);
        }
Example #8
0
        public static GameObject Get(string path)
        {
            GameObjectCeil ceil = GetFromPool(path);

            if (null == ceil)
            {
                ceil = GetFromLoad(path);
            }
            if (null == ceil)
            {
                return(null);
            }
            CreatDict(path);
            ceil.SetBeingUse(true);
            m_using[path].Add(ceil);

            return(ceil.TheGameobject);
        }