44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
#endif
|
|
|
|
public class GameStateManagerController : MonoBehaviour
|
|
{
|
|
[Tooltip("Selected state will be applied when the game starts or on the button press")]
|
|
public GameState ChangeToState;
|
|
|
|
private void Awake()
|
|
{
|
|
//Change game state to selected in inspector state when the game starts
|
|
GameStateManager.Instance.ChangeState(ChangeToState);
|
|
}
|
|
|
|
private void OnApplicationQuit()
|
|
{
|
|
//Change game state back to entry state when exiting playing mode
|
|
GameStateManager.Instance.ChangeState(GameState.Enter);
|
|
}
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
[CustomEditor(typeof(GameStateManagerController))]
|
|
class GameStateManagerControllerEditor : Editor
|
|
{
|
|
public override void OnInspectorGUI()
|
|
{
|
|
DrawDefaultInspector();
|
|
|
|
var gameStateManagerController = (GameStateManagerController)target;
|
|
if (gameStateManagerController == null) return;
|
|
|
|
//Custom button to change game state from inspector during runtime
|
|
if (GUILayout.Button("Change State"))
|
|
{
|
|
if (Application.isPlaying) GameStateManager.Instance.ChangeState(gameStateManagerController.ChangeToState);
|
|
}
|
|
}
|
|
}
|
|
#endif |