public EnemyPool(EnemyData enemyData) { _enemyPool = new Dictionary <string, HashSet <Rigidbody2D> >(); _data = enemyData; if (!_rootPool) { _rootPool = new GameObject(POOL_ENEMIES).transform; } _asteroidInitialization = new EnemyInitialization(new AsteroidFactory(enemyData), enemyData.AsteroidData); _cometInitialization = new EnemyInitialization(new CometFactory(enemyData), enemyData.CometData); _hunterInitialization = new EnemyInitialization(new HunterFactory(enemyData), enemyData.HunterData); }
private Rigidbody2D ActivateEnemy(HashSet <Rigidbody2D> enemies, EnemyInitialization initialize, int poolSize) { var enemy = enemies.FirstOrDefault(a => !a.gameObject.activeSelf); if (enemy == null) { for (var i = 0; i < poolSize; i++) { var instantiate = initialize.GetEnemy(); ReturnToPool(instantiate.transform); enemies.Add(instantiate); } ActivateEnemy(enemies, initialize, poolSize); } enemy = enemies.FirstOrDefault(a => !a.gameObject.activeSelf); return(enemy); }
void Awake() { Instance = this; }