119 lines
3.0 KiB
C#
119 lines
3.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class WaveManager : MonoBehaviour
|
|
{
|
|
protected enum WaveStatus
|
|
{
|
|
NotRunning,
|
|
Running,
|
|
Paused
|
|
};
|
|
protected WaveStatus status = WaveStatus.NotRunning;
|
|
|
|
protected int waveNumber = 0;
|
|
protected WaveObject waveObject;
|
|
protected AbstractWaveLogic waveLogic;
|
|
|
|
protected List<GameObject> spawnPoints;
|
|
protected List<GameObject> destinationPoints;
|
|
|
|
private IEnumerator coroutine;
|
|
private delegate IEnumerator MethodDelegate();
|
|
|
|
|
|
#region Activation Start/End
|
|
public void SetToStart()
|
|
{
|
|
UpdateCoroutine(ActivateStartWave);
|
|
}
|
|
|
|
private IEnumerator ActivateStartWave()
|
|
{
|
|
if(waveObject.intermissionWaveDelay > 0)
|
|
yield return new WaitForSecondsRealtime((float) waveObject.intermissionWaveDelay);
|
|
|
|
while (!waveLogic.StartWaveValidation() || IsWavePaused())
|
|
{
|
|
yield return new WaitForFixedUpdate();
|
|
}
|
|
|
|
waveLogic.StartWave(waveNumber);
|
|
status = WaveStatus.Running;
|
|
waveNumber += 1;
|
|
|
|
GameObject musicManager = GameObject.FindGameObjectWithTag("MusicManager");
|
|
musicManager.GetComponent<MusicManager>().enabled = true;
|
|
|
|
PopupUI popup = GameObject.FindGameObjectWithTag("Popup").GetComponent<PopupUI>();
|
|
popup.SetPopup("Début de vague!");
|
|
|
|
UpdateCoroutine(ActivateEndWave);
|
|
}
|
|
|
|
private IEnumerator ActivateEndWave()
|
|
{
|
|
while (!waveLogic.EndWaveValidation() || IsWavePaused())
|
|
{
|
|
yield return new WaitForFixedUpdate();
|
|
}
|
|
|
|
GameObject.FindGameObjectWithTag("Player")?.GetComponent<PlayerManagement>().AddPoints(waveObject.endWaveRewardPoints, false);
|
|
|
|
SetToStart();
|
|
status = WaveStatus.NotRunning;
|
|
|
|
UpdateCoroutine(ActivateStartWave);
|
|
|
|
MusicManager musicManager = GameObject.FindGameObjectWithTag("MusicManager").GetComponent<MusicManager>();
|
|
musicManager.StopGameMusic();
|
|
|
|
PopupUI popup = GameObject.FindGameObjectWithTag("Popup").GetComponent<PopupUI>();
|
|
popup.SetPopup("Vague repoussée!");
|
|
|
|
GetComponent<StoreManager>().OpenStore();
|
|
}
|
|
#endregion
|
|
|
|
#region Pause Actions
|
|
public void ActivatePauseWave()
|
|
{
|
|
status = WaveStatus.Paused;
|
|
}
|
|
|
|
public void ActivateUnpauseWave()
|
|
{
|
|
status = WaveStatus.Running;
|
|
}
|
|
#endregion
|
|
|
|
#region Utils
|
|
public void Prepare(WaveObject wo, AbstractWaveLogic wl)
|
|
{
|
|
waveObject = wo;
|
|
waveLogic = wl;
|
|
waveLogic.Setup(waveObject);
|
|
}
|
|
|
|
public bool IsWavePaused()
|
|
{
|
|
return status == WaveStatus.Paused;
|
|
}
|
|
|
|
private void UpdateCoroutine(MethodDelegate method)
|
|
{
|
|
if (coroutine != null)
|
|
StopCoroutine(coroutine);
|
|
|
|
coroutine = method();
|
|
StartCoroutine(coroutine);
|
|
}
|
|
|
|
public void DestroyActions()
|
|
{
|
|
StopCoroutine(coroutine);
|
|
}
|
|
#endregion
|
|
}
|