118 lines
2.4 KiB
C#
118 lines
2.4 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.Events;
|
||
using UnityEngine.SceneManagement;
|
||
using UnityEngine.UI;
|
||
|
||
|
||
public enum GameState
|
||
{
|
||
None,
|
||
Started,
|
||
Ended,
|
||
}
|
||
|
||
public class GameManager : MonoBehaviour
|
||
{
|
||
public static GameManager Instance { get; private set; }
|
||
|
||
private EnergyController _energyController;
|
||
private vTimerCounter _timerCounter;
|
||
private EndGameModule _endGameModule;
|
||
|
||
private bool _successEnd;
|
||
|
||
public UnityEvent OnGameStarted;
|
||
public UnityEvent OnGameEnded;
|
||
|
||
public GameState CurrentGameState = GameState.None;
|
||
|
||
|
||
private void Awake()
|
||
{
|
||
if (!Instance)
|
||
{
|
||
Instance = this;
|
||
}
|
||
else
|
||
{
|
||
Destroy(gameObject);
|
||
return;
|
||
}
|
||
|
||
InitReferences();
|
||
}
|
||
|
||
private void OnEnable()
|
||
{
|
||
_timerCounter.OnTimeEnded.AddListener(OnEndTime);
|
||
}
|
||
|
||
private void OnDisable()
|
||
{
|
||
_timerCounter.OnTimeEnded.AddListener(OnEndTime);
|
||
}
|
||
|
||
private void InitReferences()
|
||
{
|
||
_endGameModule = FindObjectOfType<EndGameModule>();
|
||
_timerCounter = FindObjectOfType<vTimerCounter>();
|
||
}
|
||
|
||
public void ChangeState(GameState newState)
|
||
{
|
||
if (CurrentGameState == newState)
|
||
return;
|
||
|
||
CurrentGameState = newState;
|
||
|
||
Debug.Log(newState);
|
||
|
||
switch (CurrentGameState)
|
||
{
|
||
case GameState.Started:
|
||
{
|
||
PlayerSetup.Instance.CreateNewPlayer();
|
||
|
||
OnGameStarted?.Invoke();
|
||
}
|
||
break;
|
||
case GameState.Ended:
|
||
{
|
||
OnGameEnded?.Invoke();
|
||
_endGameModule.ShowEndMenu(_successEnd);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
private bool _startedOnce = false;
|
||
|
||
public UITextShow TextShow;
|
||
|
||
[ContextMenu("Debug Start")]
|
||
public void OnStartGame()
|
||
{
|
||
if (_startedOnce)
|
||
return;
|
||
|
||
_startedOnce = true;
|
||
TextShow.ShowTimer(3, "<22><><EFBFBD><EFBFBD><EFBFBD>!", 1, null, ()=> ChangeState(GameState.Started));
|
||
}
|
||
|
||
[ContextMenu("Debug End")]
|
||
public void OnEndTime()
|
||
{
|
||
_successEnd = false;
|
||
ChangeState(GameState.Ended);
|
||
}
|
||
|
||
[ContextMenu("Debug Finish")]
|
||
public void OnFinish()
|
||
{
|
||
_successEnd = true;
|
||
ChangeState(GameState.Ended);
|
||
}
|
||
}
|