Esempio n. 1
0
 public static void ReduceActiveNode(PoolNodeBase node, string ObjName)
 {
     if (_activeNode.ContainsKey(ObjName) && _activeNode[ObjName].Contains(node))
     {
         _activeNode[ObjName].Remove(node);
     }
 }
Esempio n. 2
0
        public PoolNodeBase GetNode(string ObjName)
        {
            ListPool     pool = GetListPool(ObjName);
            PoolNodeBase node = pool.Get();

            return(node);
        }
Esempio n. 3
0
 internal void Release(PoolNodeBase element)
 {
     if (_List.Count > 0 && _List.Contains(element))
     {
         Debug.LogWarning("对象池释放错误。试图释放一个已经释放的对象池" + element.name);
     }
     if (_ActionOnRelease != null)
     {
         _ActionOnRelease(element);
     }
     _List.Add(element);
 }
Esempio n. 4
0
        private ListPool GetListPool(string ObjName)
        {
            //通过 对象名 获得对应的对象池
            ListPool pool = null;

            if (_dictPool.Count > 0 && _dictPool.ContainsKey(ObjName))
            {
                pool = _dictPool[ObjName];
                if (pool != null)
                {
                    return(pool);
                }
            }

            CreatNode <PoolNodeBase> creatNode;

            _creatNode.TryGetValue(ObjName, out creatNode);
            if (creatNode == null)
            {
                ObjName = ObjName.Replace("(Clone)", "");
                _creatNode.TryGetValue(ObjName, out creatNode);
            }

            if (creatNode != null)
            {
                pool = new ListPool(creatNode, s => s.GetNodeCallBack(), s => s.ReleaseNodeCallBack(), RemovePoolByDic);
                _dictPool.Add(ObjName, pool);
            }
            else
            {
                creatNode = () =>
                {
                    GameObject go = Object.Instantiate(objDic[ObjName]);
                    go.name = go.name.Replace("(Clone)", "");
                    PoolNodeBase node = go.GetComponent <PoolNodeBase>();
                    if (node == null)
                    {
                        Debug.LogError("Don'Current Hvae PoolNodeBase");
                    }

                    node.nodeParent = IPoolMgrBase.Instance.transform;


                    return(go.GetComponent <PoolNodeBase>());
                };
                pool = new ListPool(creatNode, s => s.GetNodeCallBack(), s => s.ReleaseNodeCallBack(), RemovePoolByDic);
                _dictPool.Add(ObjName, pool);
                //Debug.LogError("对象没有创建方法" +ObjName);
            }

            return(pool);
        }
Esempio n. 5
0
        public static void AddActiveNode(string ObjName, PoolNodeBase node)
        {
            if (node != null)
            {
                if (!_activeNode.ContainsKey(ObjName))
                {
                    List <PoolNodeBase> list = new List <PoolNodeBase>();
                    _activeNode.Add(ObjName, list);
                }

                _activeNode[ObjName].Add(node);
            }
        }
Esempio n. 6
0
        internal void ElementDestory(PoolNodeBase element)
        {
            //判断栈中是否存在 如果存在 则移除
            string name = element.gameObject.name;

            if (_List.Contains(element))
            {
                _List.Remove(element);
            }

            countAll--;
            if (countAll <= 0)
            {
                RemovePoolListByDic(name);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Update中 对象预加载
        /// </summary>
        private void UpdatePreLoad()
        {
            if (_preLoadList == null || _preLoadIndex == _preLoadList.Count)
            {
                return;
            }

            for (int i = _preLoadIndex; i < _preLoadList.Count;)
            {
                PoolNodeBase node = _pools.GetNode(_preLoadList[i]);
                _preLoadNode.Add(node);
                node.gameObject.SetActive(false);
                _preLoadIndex++;
                break;
            }

            if (_preLoadIndex == _preLoadList.Count)
            {
                foreach (PoolNodeBase node in _preLoadNode)
                {
                    node.ReleaseNode();
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 对象销毁调取的方法
        /// 将对象从对象池中移除
        /// 不要主动调取
        /// </summary>
        /// <param UIName="Obj"></param>
        public void ElementDestory(PoolNodeBase Obj)
        {
            ListPool pool = GetListPool(Obj.gameObject.name);

            pool.ElementDestory(Obj);
        }
Esempio n. 9
0
        public void ReleaseNode(PoolNodeBase nodeBase, string ObjName)
        {
            ListPool pool = GetListPool(ObjName);

            pool.Release(nodeBase);
        }
Esempio n. 10
0
        public PoolNodeBase GetNode(string ObjName = null)
        {
            PoolNodeBase node = Get();

            return(node);
        }
Esempio n. 11
0
 void IPoolBase.ElementDestory(PoolNodeBase element)
 {
     ElementDestory(element);
     ReduceActiveNode(element, element.name);
 }
Esempio n. 12
0
        public void ReleaseNode(PoolNodeBase nodeBase, string ObjName)
        {
            Release(nodeBase);

            ReduceActiveNode(nodeBase, ObjName);
        }