Example #1
0
 /// <summary>
 /// 创建
 /// </summary>
 /// <param name="poolName"></param>
 /// <param name="prefab"></param>
 /// <param name="maxCount"></param>
 /// <param name="initCount"></param>
 public void CreatePool(string poolName, GameObject prefab, int maxCount, int initCount)
 {
     if (!m_poolDic.ContainsKey(poolName))
     {
         GameObject cGo = new GameObject(poolName);
         cGo.transform.SetParent(transform);
         GameObjectPoolContainer c = new GameObjectPoolContainer(poolName, prefab, maxCount, initCount, cGo.transform);
         m_poolDic.Add(poolName, c);
     }
 }
Example #2
0
        /// <summary>
        /// 回收
        /// </summary>
        /// <param name="pgo"></param>
        public bool Recycle(PoolGameObject pgo)
        {
            GameObjectPoolContainer pc = null;

            if (!m_poolDic.TryGetValue(pgo.poolName, out pc))
            {
                Debug.LogError(string.Format("GameObject Pool Recycle Error. You need to create {0} Pool.", pgo.poolName));
                return(false);
            }
            return(pc.Recycle(pgo));
        }
Example #3
0
        /// <summary>
        /// 分配
        /// </summary>
        /// <param name="parent"></param>
        public PoolGameObject Allocate(string poolName, Transform parent = null)
        {
            GameObjectPoolContainer pc = null;

            if (!m_poolDic.TryGetValue(poolName, out pc))
            {
                Debug.LogError(string.Format("GameObject Pool Allocate Error. You need to create {0} Pool.", poolName));
                return(null);
            }
            return(pc.Allocate(parent));
        }