コード例 #1
0
ファイル: Level.cs プロジェクト: Sikny/Projet3DJV3A
        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;
        }
コード例 #2
0
ファイル: Level.cs プロジェクト: Sikny/Projet3DJV3A
 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);
         }
     }
 }
コード例 #3
0
ファイル: Level.cs プロジェクト: Sikny/Projet3DJV3A
        // CUSTOM LEVELS
        private void LoadEnnemiesRule()
        {
            Random rando = new Random();

            foreach (var spawn in rule.localSpawnDifficulty)
            {
                if (rand.Range(0, 4 * 128) <= spawn.Value * 128 && (int)spawn.Key.X % 3 == 0 &&
                    (int)spawn.Key.Z % 3 == 0)
                {
                    EnemySpawn es = new EnemySpawn();

                    es.position = new Vector2(spawn.Key.X - rule.size / 2f, spawn.Key.Z - rule.size / 2f);
                    //es.spawnTime = counter == 0 ? 0 : Random.Range(0, 60);

                    Array values = Enum.GetValues(typeof(EntityType));
                    es.entityType = (EntityType)values.GetValue(rando.Next(values.Length));


                    es.entityType = GenRandomParam.SoftEntityType(rando, es.entityType, 0.25f);
                    enemySpawns.Add(es);
                }
            }
        }