Пример #1
0
 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);
 }
Пример #2
0
        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);
        }
Пример #3
0
 void Awake()
 {
     Instance = this;
 }