45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
|
using UnityEngine;
|
||
|
|
||
|
/// <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>
|
||
|
/// 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);
|
||
|
}
|
||
|
}
|
||
|
}
|