//o(1) private void AddObjectToPool(PoolObject po) { //add to pool po.gameObject.SetActive(false); availableObjStack.Push(po); po.isPooled = true; po.transform.SetParent(poolRoot, false); }
public void ReturnObjectToPool(PoolObject po) { if (this.poolName.Equals(po.poolName)) { if (po.isPooled) { Debug.LogWarning(po.gameObject.name + " is already in pool. Why are you trying to return it again? Check usage."); } else { this.AddObjectToPool(po); } } else { Debug.LogError(string.Format("Trying to add object to incorrect pool {0} {1}", po.poolName, this.poolName)); } }
//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) { } else { AddObjectToPool(po); } } else { } }
public void ReturnObjectToPool(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); } } }
//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)); } }
//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)); } }