73 lines
No EOL
2 KiB
C#
73 lines
No EOL
2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
/// <summary>
|
|
/// singleton for a single source of truth game state and flow management
|
|
/// </summary>
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// enum for available menus in the game, for use with <c>ShowMenu()</c>
|
|
/// </summary>
|
|
public enum DisplayState
|
|
{
|
|
ScreenStart,
|
|
OverlayAccountManagement,
|
|
OverlaySettings,
|
|
OverlayLeaderboard,
|
|
Game,
|
|
UnassociatedState
|
|
}
|
|
|
|
/// <summary>
|
|
/// singleton pattern: define instance field for accessing the singleton elsewhere
|
|
/// </summary>
|
|
public static GameManager Instance;
|
|
|
|
/// <summary>
|
|
/// the visual element object for game ui (hud/prompts/tooltips)
|
|
/// </summary>
|
|
private VisualElement _ui;
|
|
|
|
/// <summary>
|
|
/// backend object for handling communication with the firebase backend
|
|
/// </summary>
|
|
public Backend Backend;
|
|
|
|
/// <summary>
|
|
/// enforces singleton behaviour; sets doesn't destroy on load and checks for multiple instances
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// called when the game object is enabled
|
|
/// </summary>
|
|
private void OnEnable()
|
|
{
|
|
Backend = new Backend();
|
|
Backend.Initialise();
|
|
}
|
|
|
|
/// <summary>
|
|
/// called when the game object is disabled
|
|
/// </summary>
|
|
private void OnDestroy()
|
|
{
|
|
Backend.Cleanup();
|
|
}
|
|
} |