using UnityEngine;
using UnityEngine.UIElements;
/// <summary>
/// singleton for a single source of truth game state and flow management
/// </summary>
public class GameManager : MonoBehaviour
{
/// enum for available menus in the game, for use with <c>ShowMenu()</c>
public enum DisplayState
ScreenStart,
OverlayAccountManagement,
OverlaySettings,
OverlayLeaderboard,
Game,
UnassociatedState
}
/// singleton pattern: define instance field for accessing the singleton elsewhere
public static GameManager Instance;
/// the visual element object for game ui (hud/prompts/tooltips)
private VisualElement _ui;
/// backend object for handling communication with the firebase backend
public Backend Backend;
/// enforces singleton behaviour; sets doesn't destroy on load and checks for multiple instances
private void Awake()
// check if instance hasn't been set yet
if (Instance == null)
Debug.Log("awake as singleton instance, setting self as the forever-alive instance");
Instance = this;
DontDestroyOnLoad(gameObject);
// check if instance is already set and it's not this instance
else if (Instance != null && Instance != this)
Debug.Log("awake as non-singleton instance, destroying self");
Destroy(gameObject);
/// called when the game object is enabled
private void OnEnable()
Backend = new Backend();
Backend.Initialise();
/// called when the game object is disabled
private void OnDestroy()
Backend.Cleanup();