Ver.0.3.0.33
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using AibisDream.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
public class ActionKitMonoBehaviourEvents : Singleton<ActionKitMonoBehaviourEvents>
|
||||
{
|
||||
public EasyEvent OnUpdate { get; private set; }
|
||||
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;
|
||||
OnUpdate = new EasyEvent();
|
||||
}
|
||||
|
||||
public override void OnSingletonDestroy()
|
||||
{
|
||||
OnUpdate.UnRegisterAll();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
_onApplicationQuitEvent?.Trigger();
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user