Exemple #1
0
 public bool GetWaveData(int index, out WaveStruct waveData)
 {
     if (waveList.TryGetValue(index, out waveData) == false)
     {
         Debug.LogWarning("not existed Data: " + index.ToString());
         return(false);
     }
     return(true);
 }
    void SetNewWave()
    {
        //current wave and update UI
        WaveStruct wave = waveConfig.Waves[CurrentWave];

        GameManager.instance.uiManager.UpdateCurrentLevelText(CurrentWave);

        //update level config (change level) and update resources for player
        GameManager.instance.levelManager.UpdateLevel(wave.LevelConfig);
        GameManager.instance.player.CurrentResources += wave.resourcesMax;
    }
    IEnumerator Wave_Coroutine()
    {
        //current wave
        WaveStruct wave = waveConfig.Waves[CurrentWave];

        //foreach enemy in this wave, instantiate but deactivate
        foreach (Enemy enemy in wave.Enemies)
        {
            InstantiateNewEnemy(enemy);
            yield return(null);
        }

        //enemies copy(copy because when enemy is killed, it's removed from list)
        List <Enemy> enemiesCopy = enemies.CreateCopy();

        //queue to not spawn on same face
        Queue <EFace> facesQueue = new Queue <EFace>();

        //for every enemy
        foreach (Enemy enemy in enemiesCopy)
        {
            //randomize coordinates to attack
            EFace       face = WorldUtility.GetRandomFace(facesQueue, waveConfig.Waves[CurrentWave].IgnorePreviousFacesAtSpawn);
            int         x    = Random.Range(0, GameManager.instance.world.worldConfig.NumberCells);
            int         y    = Random.Range(0, GameManager.instance.world.worldConfig.NumberCells);
            Coordinates coordinatesToAttack = new Coordinates(face, x, y);

            //get position and rotation
            Vector3    position;
            Quaternion rotation;
            GameManager.instance.world.GetPositionAndRotation(coordinatesToAttack, waveConfig.Waves[CurrentWave].DistanceFromWorld, out position, out rotation);

            //set enemy position and rotation, then activate
            enemy.transform.position = position;
            enemy.transform.rotation = rotation;

            //instantiate portal at position and rotation
            if (GameManager.instance.levelManager.generalConfig.PortalPrefab)
            {
                Instantiate(GameManager.instance.levelManager.generalConfig.PortalPrefab, position, rotation);
            }

            //set enemy destination and activate
            enemy.Init(coordinatesToAttack);

            //wait for next enemy
            yield return(new WaitForSeconds(wave.TimeBetweenSpawns));
        }
    }
Exemple #4
0
 public void InitSpawner(WaveStruct wave)
 {
     _currentWave = wave;
 }