122 lines
2.5 KiB
C#
122 lines
2.5 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 vTimerCounter _timerCounter;
|
||
private EndGameModule _endGameModule;
|
||
|
||
private bool _successEnd;
|
||
|
||
public UnityEvent OnGameInit;
|
||
public UnityEvent OnGameStarted;
|
||
public UnityEvent OnGameEnded;
|
||
|
||
public GameState CurrentGameState = GameState.None;
|
||
|
||
|
||
private void Awake()
|
||
{
|
||
if (Instance == null)
|
||
{
|
||
Instance = this;
|
||
}
|
||
else if (Instance != this)
|
||
{
|
||
Destroy(gameObject);
|
||
return;
|
||
}
|
||
|
||
InitReferences();
|
||
}
|
||
|
||
private void OnEnable()
|
||
{
|
||
_timerCounter.OnTimeEnded.AddListener(OnEndTime);
|
||
}
|
||
|
||
private void OnDisable()
|
||
{
|
||
_timerCounter.OnTimeEnded.AddListener(OnEndTime);
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
LeaderboardController.Instance.RefreshEntries();
|
||
}
|
||
|
||
private void InitReferences()
|
||
{
|
||
_endGameModule = FindObjectOfType<EndGameModule>();
|
||
_timerCounter = FindObjectOfType<vTimerCounter>();
|
||
|
||
OnGameInit?.Invoke();
|
||
}
|
||
|
||
public void ChangeState(GameState newState)
|
||
{
|
||
if (CurrentGameState == newState)
|
||
return;
|
||
|
||
CurrentGameState = newState;
|
||
switch (CurrentGameState)
|
||
{
|
||
case GameState.Started:
|
||
{
|
||
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>!", 0, null, ()=> ChangeState(GameState.Started));
|
||
}
|
||
|
||
[ContextMenu("Debug End")]
|
||
public void OnEndTime()
|
||
{
|
||
//_successEnd = false;
|
||
//ChangeState(GameState.Ended);
|
||
BNG.SceneLoader.Instance.LoadStartScene();
|
||
}
|
||
|
||
[ContextMenu("Debug Finish")]
|
||
public void OnFinish()
|
||
{
|
||
//_successEnd = true;
|
||
//ChangeState(GameState.Ended);
|
||
BNG.SceneLoader.Instance.LoadStartScene();
|
||
}
|
||
}
|