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; Debug.Log($"Change GameState [{CurrentGameState}]=>[{newState}]", this); 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() { Debug.Log($"Try start. Flag: {_startedOnce}", this); if (_startedOnce) return; _startedOnce = true; Debug.Log($"Try run timer", this); TextShow.ShowTimer(3, "СТАРТ!", 1, null, () => { Debug.Log($"End timer. Change game to start", this); ChangeState(GameState.Started); }); } }