This repository has been archived on 2024-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
colourmeok/ColourMeOKGame/Assets/Scripts/GameManager.cs

73 lines
2 KiB
C#
Raw Normal View History

2024-11-15 07:54:43 +08:00
using UnityEngine;
2024-11-17 07:29:22 +08:00
using UnityEngine.UIElements;
2024-11-15 07:54:43 +08:00
/// <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;
2024-11-17 07:29:22 +08:00
/// <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;
2024-11-15 07:54:43 +08:00
/// <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);
}
}
2024-11-17 07:29:22 +08:00
/// <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();
}
2024-11-15 07:54:43 +08:00
}