Exemplo n.º 1
0
        public void Despawn(GameObject go)
        {
            PoolObject po = go.GetComponent <PoolObject>();

            if (po == null)
            {
                Debug.LogWarning("Specified object is not a pooled instance: " + go.name);
            }
            else
            {
                if (poolDictionary.ContainsKey(po.poolName))
                {
                    Pool pool = poolDictionary[po.poolName];
                    pool.ReturnObjectToPool(po);
                }
                else
                {
                    Debug.LogWarning("No pool available with name: " + po.poolName);
                }
            }
        }
Exemplo n.º 2
0
 //o(1)
 public void ReturnObjectToPool(PoolObject po)
 {
     if (poolName.Equals(po.poolName))
     {
         /* we could have used availableObjStack.Contains(po) to check if this object is in pool.
          * While that would have been more robust, it would have made this method O(n)
          */
         if (po.isPooled)
         {
             Debug.LogWarning(po.gameObject.name + " is already in pool. Why are you trying to return it again? Check usage.");
         }
         else
         {
             AddObjectToPool(po);
         }
     }
     else
     {
         Debug.LogError(string.Format("Trying to add object to incorrect pool {0} {1}", po.poolName, poolName));
     }
 }