Exemplo n.º 1
0
        public IEnumerator StartLevel()
        {
            for (int i = _waitingSpawners.Count - 1; i >= 0; --i)
            {
                _waitingSpawners[i].SetAnimating(false);
                _waitingSpawners[i].DeInit();
            }

            _waitingSpawners.Clear();
            _playerUnits = new List <PlayerUnit>();
            Transform newUnit;

            for (int i = enemySpawns.Count - 1; i >= 0; i--)
            {
                EnemySpawn current = enemySpawns[0];
                var        offset  = Vector3.right * (TerrainGrid.Width / 2f) +
                                     Vector3.forward * (TerrainGrid.Height / 2f);
                Vector3 position = new Vector3(current.position.x, SystemUnit.YPos, current.position.y) + offset;

                // enemy spawn (can be delayed)
                if (current.spawnTime > 0)
                {
                    // todo update delayed calls when finished
                    _enemySpawnsDelayedCalls.Add(DOVirtual.DelayedCall(
                                                     Mathf.Max(0f, current.spawnTime - Spawner.timeToSpawn), () => {
                        Spawner spawner            = (Spawner)PoolManager.Instance().GetPoolableObject(typeof(Spawner));
                        spawner.transform.position = position;
                        spawner.Init(current.entityType);

                        _spawningEnemies.Add(DOVirtual.DelayedCall(Spawner.timeToSpawn, () => {
                            spawner.DeInit();
                            newUnit = _systemUnit.SpawnUnit(current.entityType, _systemUnit.aiUnitPrefab,
                                                            position);
                            livingEnemies.Add(newUnit);
                        }).OnUpdate(() => { spawner.UpdateTime(); }));
                    }));
                }
                else
                {
                    newUnit = _systemUnit.SpawnUnit(current.entityType, _systemUnit.aiUnitPrefab,
                                                    position);
                    livingEnemies.Add(newUnit);
                }

                enemySpawns.Remove(current);

                yield return(null);
            }

            GameSingleton.Instance.ResumeGame();
            _levelStarted = true;
        }
Exemplo n.º 2
0
 private void ShowNextSpawns()
 {
     for (int i = enemySpawns.Count - 1; i >= 0; --i)
     {
         EnemySpawn current = enemySpawns[i];
         if (Math.Abs(current.spawnTime) < 0.001f)
         {
             var offset = Vector3.right * (TerrainGrid.Width / 2f) +
                          Vector3.forward * (TerrainGrid.Height / 2f);
             Vector3 position = new Vector3(current.position.x, SystemUnit.YPos, current.position.y) + offset;
             Spawner spawner  = (Spawner)PoolManager.Instance().GetPoolableObject(typeof(Spawner));
             spawner.transform.position = position;
             spawner.Init(current.entityType);
             spawner.SetAnimating(true);
             _waitingSpawners.Add(spawner);
         }
     }
 }