示例#1
0
        private Wave getNextPresetWave(out bool isBoss)
        {
            // Try to get the first wave
            if (activeWave == null)
            {
                if (userWaves != null && userWaves.Length > 0)
                {
                    isBoss = false;
                    return(userWaves[0]);
                }
            }

            // Make sure the wave is valid
            if (currentIndex - 1 < userWaves.Length)
            {
                // Get the next wave
                Wave result = userWaves[currentIndex - 1];

                // Trigger event
                if (onWaveProgress != null)
                {
                    onWaveProgress(activeWave.calculateAdvanceRate(result));
                }

                isBoss = false;
                return(result);
            }

            // Looks like we have completed our wave list
            switch (onComplete)
            {
            case WavesCompleteAction.DoNothing:
            {
                // Revert to last
                currentIndex--;
                currentWave--;

                // Trigger last wave
                if (onExitLastWave != null)
                {
                    onExitLastWave(activeWave);
                }
            }
            break;

            case WavesCompleteAction.RepeatFromStart:
            {
                // Reset
                reset(true);

                // Reccursive call
                isBoss = false;
                return(getNextWave(out isBoss));
            }

            case WavesCompleteAction.RepeatLast:
            {
                // Get the last wave
                isBoss = false;
                return(userWaves[userWaves.Length - 1]);
            }
            }

            isBoss = false;
            return(null);
        }
示例#2
0
        private IEnumerator waveRountine()
        {
            bool bossWave = false;
            Wave lastWave = activeWave;

            // Get the wave
            Wave wave = getNextWave(out bossWave);

            // Make sure we have a valid wave
            if (wave == null)
            {
                yield break;
            }

            activeWave = wave;

            if (bossWave == false)
            {
                // Trigger wave started
                onWaveStarted();
            }
            else
            {
                // Trigger the wave event
                if (bossRoundIsWave == true)
                {
                    onWaveStarted();
                }

                // Trigger the boss wave start
                onBossWaveStarted();
            }

            // Wait for the start delay
            yield return(new WaitForSeconds(activeWave.waveStartDelay));

            // Begin spawning
            for (int i = 0; i < activeWave.spawnCount; i++)
            {
                // Make sure there is room for more spawnables
                while (InstancesRemaining >= maximumSpawnedItems)
                {
                    yield return(null);
                }

                // Spawn flag
                bool canSpawn = false;

                // Get the spawn manager
                SpawnBase spawn = (activeWave.spawnManager != null) ? activeWave.spawnManager : spawnManager;

                // Wait until we can spawn
                while (canSpawn == false)
                {
                    // Check if we are able to spawn
                    canSpawn = spawn.canSpawn();
                    yield return(null);
                }

                // Spawn the enemy
                spawn.spawn();
                spawnedCount++;

                // Wait for next spawn
                yield return(new WaitForSeconds(activeWave.randomSpawnDelay()));
            }

            // Wait for all enemies to become dead
            if (activeWave.waitForDead == true)
            {
                while (InstancesRemaining > 0)
                {
                    yield return(null);
                }
            }

            // Wait for end of wave delay
            yield return(new WaitForSeconds(activeWave.waveCompleteDelay));

            if (bossWave == false)
            {
                // Trigger wave end
                onWaveEnded();
            }
            else
            {
                // Trigger boss wave end
                onBossWaveEnded();

                // Trigger wave end event
                if (bossRoundIsWave == true)
                {
                    if (onExitWave != null)
                    {
                        onExitWave(activeWave);
                    }
                }

                // Revert to the previous wave so that wave advance works correctly
                activeWave = lastWave;
            }
        }