Gameplay-Edit
This commit is contained in:
58
Assets/Scripts/GameManager.cs
Normal file
58
Assets/Scripts/GameManager.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user