private void CreateInitialPoolObjects() { for (int i = initialPoolObjects.Length - 1; i >= 0; i--) { PoolAmount poolAmount = initialPoolObjects[i]; GameObject poolGameObject = poolAmount.gameObject; CheckContainers(poolGameObject); for (int j = poolAmount.ammount; j > 0; j--) { GameObject newGameObject = Instantiate(poolGameObject, Vector3.zero, Quaternion.identity); newGameObject.name = poolGameObject.name; newGameObject.transform.parent = containers[newGameObject.name].transform; PoolObject newPoolObject = CreateGenericPoolObject(newGameObject); newPoolObject.IsActive = false; inactivePoolObjects[poolGameObject.name].Push(newPoolObject); } } initialPoolObjects = null; }
public GenericPool(int initialStock, CallbackFactory factoryMethod, PoolObject <T> .PoolCallback init, PoolObject <T> .PoolCallback dispose) { poolStack = new Stack <PoolObject <T> >(); activePoolStack = new Stack <PoolObject <T> >(); this.factoryMethod = factoryMethod; this.init = init; this.dispose = dispose; for (int i = 0; i < initialStock; i++) { poolStack.Push(new PoolObject <T>(this.factoryMethod(), this.init, this.dispose)); } }