using System; using UnityEngine; namespace UnityAtoms.FSM { public class FiniteStateMachineMonoHook : MonoBehaviour { public static FiniteStateMachineMonoHook GetInstance(bool createIfNotExist = false) { if (_instance == null && createIfNotExist) { GameObject go = new GameObject("FiniteStateMachineUpdateHook"); _instance = go.AddComponent(); } return _instance; } public event Action OnStart; public event Action OnUpdate; public event Action OnFixedUpdate; private static FiniteStateMachineMonoHook _instance; private void Awake() { if (_instance != null && _instance != this) { Destroy(gameObject); return; } _instance = this; } private void Start() { if (OnStart != null) { OnStart.Invoke(); } } private void Update() { if (OnUpdate != null) { OnUpdate.Invoke(Time.deltaTime); } } private void FixedUpdate() { if (OnFixedUpdate != null) { OnFixedUpdate.Invoke(Time.deltaTime); } } } }