public static void TriggerGlobalEvent(string globalEventName, Wave wave)
    {
        WaveEvent thisEvent = null;

        if (instance.waveEventDictionary.TryGetValue(globalEventName, out thisEvent))
        {
            thisEvent.Invoke(wave);
        }
    }
示例#2
0
    void UpdateValue()
    {
        float position = 0;

        switch (waveType)
        {
        case WaveType.Sine:
            _value = Mathf.Sin(_position * 4 * Mathf.PI);
            break;

        case WaveType.Saw:
            position = periodsInGraphic * (_position % (1.0f / periodsInGraphic));
            _value   = 1.0f - (2.0f * position);
            break;

        case WaveType.InverseSaw:
            position = periodsInGraphic * (_position % (1.0f / periodsInGraphic));
            _value   = (2.0f * position) - 1.0f;
            break;

        case WaveType.Square:
            position = periodsInGraphic * (_position % (1.0f / periodsInGraphic));
            _value   = (position < 0.5f) ? 1.0f : -1.0f;
            break;

        case WaveType.Triangle:
            position = periodsInGraphic * (_position % (1.0f / periodsInGraphic));
            if (position < 0.25f)
            {
                // 0 to 1
                _value = 4 * position;
            }
            else if (position < 0.5f)
            {
                // 1 to 0
                _value = 1 - (4 * (position - 0.25f));
            }
            else if (position < 0.75f)
            {
                // 0 to -1
                _value = -(4 * (position - 0.5f));
            }
            else
            {
                // -1 to 0
                _value = -1 + (4 * (position - 0.75f));
            }
            break;
        }

        _onValueChanged.Invoke(_value);
    }
示例#3
0
        private IEnumerator SpawnWave(Wave wave, bool calledEarly)
        {
            _waveNumber++;
            UiWaves.DespawnTopWave();
            if (WaveIndex != null)
            {
                WaveIndex.Value++;
            }
            TryGetNextWave(out _nextWaveWaiting);
            if (EnemiesWaiting != null)
            {
                EnemiesWaiting.Value += wave.WaveClusters.Sum(c => c.Amount);
            }

            wave.CalledEarly = calledEarly;

            if (OnWaveStarted != null)
            {
                OnWaveStarted.Invoke(wave);
            }

            for (int clusterIndex = 0; clusterIndex < wave.WaveClusters.Count; clusterIndex++)
            {
                var cluster = wave.WaveClusters[clusterIndex];

                if (!cluster.SpawnWithPreviousCluster)
                {
                    foreach (var time in SpawnCluster(wave, clusterIndex))
                    {
                        yield return(time);
                    }
                }
                else
                {
                    StartCoroutine(SpawnCluster(wave, clusterIndex).GetEnumerator());
                }
            }
        }