mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-23 16:48:23 -05:00
43 lines
1.0 KiB
C#
43 lines
1.0 KiB
C#
|
using System;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace UnityAtoms.FSM
|
||
|
{
|
||
|
public class FiniteStateMachineUpdateHook : MonoBehaviour
|
||
|
{
|
||
|
public static FiniteStateMachineUpdateHook GetInstance(bool createIfNotExist = false)
|
||
|
{
|
||
|
if (_instance == null && createIfNotExist)
|
||
|
{
|
||
|
GameObject go = new GameObject("FiniteStateMachineUpdateHook");
|
||
|
_instance = go.AddComponent<FiniteStateMachineUpdateHook>();
|
||
|
}
|
||
|
|
||
|
return _instance;
|
||
|
}
|
||
|
|
||
|
public event Action<float> OnUpdate;
|
||
|
|
||
|
private static FiniteStateMachineUpdateHook _instance;
|
||
|
|
||
|
private void Awake()
|
||
|
{
|
||
|
if (_instance != null && _instance != this)
|
||
|
{
|
||
|
Destroy(gameObject);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
_instance = this;
|
||
|
DontDestroyOnLoad(gameObject);
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
if (OnUpdate != null)
|
||
|
{
|
||
|
OnUpdate.Invoke(Time.deltaTime);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|