style: put game manager editor extension class in a separate file
This commit is contained in:
parent
3a15ce6718
commit
77eb1bc578
@ -1,9 +1,5 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
using UnityEditor;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public class GameStateController : MonoBehaviour
|
public class GameStateController : MonoBehaviour
|
||||||
{
|
{
|
||||||
[Tooltip("Selected state will be applied when the game starts or on the button press")]
|
[Tooltip("Selected state will be applied when the game starts or on the button press")]
|
||||||
@ -22,24 +18,7 @@ public class GameStateController : MonoBehaviour
|
|||||||
// Change game state back to entry state when exiting playing mode
|
// Change game state back to entry state when exiting playing mode
|
||||||
GameStateManager.Instance.ChangeState(GameState.Enter);
|
GameStateManager.Instance.ChangeState(GameState.Enter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ChangeState(string newStateStr) =>
|
||||||
|
GameStateManager.Instance.ChangeState((GameState) System.Enum.Parse(typeof(GameState), newStateStr));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
[CustomEditor(typeof(GameStateController))]
|
|
||||||
class GameStateControllerEditor : Editor
|
|
||||||
{
|
|
||||||
public override void OnInspectorGUI()
|
|
||||||
{
|
|
||||||
DrawDefaultInspector();
|
|
||||||
|
|
||||||
var gameStateController = (GameStateController)target;
|
|
||||||
if (gameStateController == null) return;
|
|
||||||
|
|
||||||
// Custom button to change game state from inspector during runtime
|
|
||||||
if (GUILayout.Button("Change State"))
|
|
||||||
{
|
|
||||||
if (Application.isPlaying) GameStateManager.Instance.ChangeState(gameStateController.ChangeToState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -0,0 +1,24 @@
|
|||||||
|
#if UNITY_EDITOR
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
[CustomEditor(typeof(GameStateController))]
|
||||||
|
class GameStateControllerEditor : Editor
|
||||||
|
{
|
||||||
|
public override void OnInspectorGUI()
|
||||||
|
{
|
||||||
|
DrawDefaultInspector();
|
||||||
|
|
||||||
|
var gameStateController = (GameStateController)target;
|
||||||
|
if (gameStateController == null) return;
|
||||||
|
|
||||||
|
// Custom button to change game state from inspector during runtime
|
||||||
|
if (GUILayout.Button("Change State"))
|
||||||
|
{
|
||||||
|
if (Application.isPlaying) GameStateManager.Instance.ChangeState(gameStateController.ChangeToState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
11
Assets/_Scripts/Managers/GameStateManager/GameStateController_CustomEditor.cs.meta
generated
Normal file
11
Assets/_Scripts/Managers/GameStateManager/GameStateController_CustomEditor.cs.meta
generated
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 515312156c02a0c279cced733921e2f3
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user