示例#1
0
        public Pool(string poolName, GameObject poolObjectPrefab, GameObject rootPoolObj, int initialCount, EPoolInflationType type)
        {
            if (poolObjectPrefab == null)
            {
#if UNITY_EDITOR
                Debug.LogError("[ObjPoolManager] null pool object prefab !");
#endif
                return;
            }
            this.poolName      = poolName;
            this.inflationType = type;
            this.rootObj       = new GameObject(poolName + "Pool");
            this.rootObj.transform.SetParent(rootPoolObj.transform, false);

            // In case the origin one is Destroyed, we should keep at least one
            GameObject go = GameObject.Instantiate(poolObjectPrefab);
            PoolObject po = go.GetComponent <PoolObject>();
            if (po == null)
            {
                po = go.AddComponent <PoolObject>();
            }
            po.poolName = poolName;
            AddObjectToPool(po);

            //populate the pool
            populatePool(Mathf.Max(initialCount, 1));
        }
示例#2
0
 public void InitPool(string poolName, int size, EPoolInflationType type = EPoolInflationType.DOUBLE)
 {
     if (poolDict.ContainsKey(poolName))
     {
         return;
     }
     else
     {
         GameObject pb = Resources.Load <GameObject>(poolName);
         if (pb == null)
         {
             Debug.LogError("[ResourceManager] Invalide prefab name for pooling :" + poolName);
             return;
         }
         poolDict[poolName] = new Pool(poolName, pb, gameObject, size, type);
     }
 }