98 lines
2.6 KiB
C#
98 lines
2.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using AibisDream.Framework;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream.Kit
|
|
{
|
|
internal class ActionKitMonoBehaviourEvents : Singleton<ActionKitMonoBehaviourEvents>
|
|
{
|
|
private readonly EasyEvent _onUpdate = new();
|
|
private readonly EasyEvent _onFixedUpdate = new();
|
|
private readonly EasyEvent _onLateUpdate = new();
|
|
private readonly EasyEvent _onGUIEvent = new();
|
|
private readonly EasyEvent<bool> _onApplicationFocusEvent = new();
|
|
private readonly EasyEvent<bool> _onApplicationPauseEvent = new();
|
|
private readonly EasyEvent _onApplicationQuitEvent = new();
|
|
|
|
public override void OnSingletonInit()
|
|
{
|
|
hideFlags = HideFlags.HideInHierarchy;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
_onUpdate?.Trigger();
|
|
|
|
QueueUpdate();
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
_onGUIEvent?.Trigger();
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
_onFixedUpdate?.Trigger();
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
_onLateUpdate?.Trigger();
|
|
}
|
|
|
|
private void OnApplicationFocus(bool hasFocus)
|
|
{
|
|
_onApplicationFocusEvent?.Trigger(hasFocus);
|
|
}
|
|
|
|
private void OnApplicationPause(bool pauseStatus)
|
|
{
|
|
_onApplicationPauseEvent?.Trigger(pauseStatus);
|
|
}
|
|
|
|
// protected override void OnApplicationQuit()
|
|
// {
|
|
// OnApplicationQuitEvent?.Trigger();
|
|
// base.OnApplicationQuit();
|
|
// }
|
|
|
|
public void ExecuteCoroutine(IEnumerator coroutine, Action onFinish)
|
|
{
|
|
StartCoroutine(DoExecuteCoroutine(coroutine, onFinish));
|
|
}
|
|
|
|
IEnumerator DoExecuteCoroutine(IEnumerator coroutine, Action onFinish)
|
|
{
|
|
yield return coroutine;
|
|
onFinish?.Invoke();
|
|
}
|
|
|
|
#region ActionQueue移植
|
|
|
|
private readonly List<IActionQueueCallback> _actionQueueCallbacks = new();
|
|
|
|
public static void AddCallback(IActionQueueCallback actionQueueCallback)
|
|
{
|
|
Instance._actionQueueCallbacks.Add(actionQueueCallback);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
private void QueueUpdate()
|
|
{
|
|
if (_actionQueueCallbacks.Count > 0)
|
|
{
|
|
foreach (var actionQueueCallback in _actionQueueCallbacks)
|
|
{
|
|
actionQueueCallback.Call();
|
|
}
|
|
|
|
_actionQueueCallbacks.Clear();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |