87 lines
1.7 KiB
C#
87 lines
1.7 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; }
|
|
|
|
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 Start()
|
|
{
|
|
LeaderboardController.Instance.RefreshEntries();
|
|
}
|
|
|
|
private void InitReferences()
|
|
{
|
|
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();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
private bool _startedOnce = false;
|
|
|
|
public UITextShow TextShow;
|
|
|
|
[ContextMenu("Debug Start")]
|
|
public void OnStartGame()
|
|
{
|
|
if (_startedOnce)
|
|
return;
|
|
|
|
_startedOnce = true;
|
|
TextShow.ShowTimer(3, "ÑÒÀÐÒ!", 1, null, ()=> ChangeState(GameState.Started));
|
|
}
|
|
}
|