59 lines
1.0 KiB
C#
59 lines
1.0 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public enum GameState
|
|
{
|
|
Editing,
|
|
Gameplay
|
|
}
|
|
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
// Static
|
|
private static GameManager instance;
|
|
|
|
// Events
|
|
public event GameStateChangedHandler GameStateChanged;
|
|
public delegate void GameStateChangedHandler(GameState newState);
|
|
|
|
// Public
|
|
public GameState currentState { get; private set; } = GameState.Editing;
|
|
|
|
// Properties
|
|
public static GameManager Instance => instance;
|
|
|
|
|
|
// Methods
|
|
private void Awake()
|
|
{
|
|
if (instance != null && instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
instance = this;
|
|
}
|
|
|
|
|
|
// Used by button OnClick
|
|
public void SetPlayState()
|
|
{
|
|
SetState(GameState.Gameplay);
|
|
}
|
|
|
|
|
|
// Use by button OnClick
|
|
public void SetEditState()
|
|
{
|
|
SetState(GameState.Editing);
|
|
}
|
|
|
|
|
|
public void SetState(GameState newState)
|
|
{
|
|
currentState = newState;
|
|
|
|
GameStateChanged?.Invoke(currentState);
|
|
}
|
|
}
|