public static PoolableObject GetNext(PoolableObject prefab) { var poolId = prefab.GetInstanceID(); if (_Pools.ContainsKey(poolId) == false) { CreatePool(prefab, INITIAL_POOL_SIZE); } var currentPoolableObjectList = _Pools[poolId]; // Return the next avaiable PoolableObject if (_Pools[poolId].Count > 0) // if the pool count is less than 0 { return(_Pools[poolId].Dequeue()); // dequeues bullet } return(AddObjectToPool(prefab, poolId)); }
public static PoolableObject GetNext(PoolableObject prefab) { var poolId = prefab.GetInstanceID(); if (_Pools.ContainsKey(poolId) == false) { CreatePool(prefab, _DEFAULT_POOL_SIZE); } var currentPoolableObjectsList = _Pools[poolId]; for (int i = 0; i < currentPoolableObjectsList.Count; i++) { _Indexes[poolId] = (_Indexes[poolId] + 1) % _Pools[poolId].Count; var checkIndex = _Indexes[poolId]; if (currentPoolableObjectsList[checkIndex].gameObject.activeInHierarchy == false) { return(currentPoolableObjectsList[checkIndex]); } } return(AddObjectToPool(prefab, poolId)); }
public static void Fetch(PoolableObject prefab, int poolId) { _Pools[prefab.poolId].Enqueue(prefab); // enques a new prefab }