public BulletPool AddPool(BulletPoolTemplate pool) { BulletPool instantiatedBullets = new BulletPool(); var bulletPrefab = pool.bulletPrefab; instantiatedBullets.Init(pool.bulletCount); for (int j = 0; j < pool.bulletCount; j++) { var bullet = Instantiate(bulletPrefab, Vector2.zero, Quaternion.identity); instantiatedBullets.bullets[j] = bullet; } instantiatedBullets.OnDispose += RemoveFromPool; pooledBullets.Add(instantiatedBullets); return(instantiatedBullets); }
public List <BulletPool> AddPools(List <BulletPoolTemplate> pools) { List <BulletPool> poolList = new List <BulletPool>(); for (int i = 0; i < pools.Count; i++) { BulletPool instantiatedBullets = new BulletPool(); var bulletPrefab = pools[i].bulletPrefab; instantiatedBullets.Init(pools[i].bulletCount); for (int j = 0; j < pools[i].bulletCount; j++) { var bullet = Instantiate(bulletPrefab, Vector2.zero, Quaternion.identity); instantiatedBullets.bullets[j] = bullet; } instantiatedBullets.OnDispose += RemoveFromPool; pooledBullets.Add(instantiatedBullets); poolList.Add(instantiatedBullets); } return(poolList); }
private void RemoveFromPool(BulletPool pool) { pooledBullets.Remove(pool); }