Move events to App class.
This commit is contained in:
@@ -9,13 +9,13 @@ namespace Utils.Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
Event("EarlyUpdate", EventManager.EarlyUpdateLength, EventManager.EarlyUpdateDelegates);
|
||||
Event("EarlyUpdate", App.EarlyUpdateLength, App.EarlyUpdateDelegates);
|
||||
EditorGUILayout.Space();
|
||||
Event("Update", EventManager.UpdateLength, EventManager.UpdateDelegates);
|
||||
Event("Update", App.UpdateLength, App.UpdateDelegates);
|
||||
EditorGUILayout.Space();
|
||||
Event("LateUpdate", EventManager.LateUpdateLength, EventManager.LateUpdateDelegates);
|
||||
Event("LateUpdate", App.LateUpdateLength, App.LateUpdateDelegates);
|
||||
EditorGUILayout.Space();
|
||||
Event("LastUpdate", EventManager.LastUpdateLength, EventManager.LastUpdateDelegates);
|
||||
Event("LastUpdate", App.LastUpdateLength, App.LastUpdateDelegates);
|
||||
}
|
||||
|
||||
private void Event(string title, int length, Delegate[] delegates)
|
||||
|
@@ -9,7 +9,7 @@ namespace Utils.Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
Event("FixedUpdate", PhysicsEventManager.FixedUpdateLength, PhysicsEventManager.FixedUpdateDelegates);
|
||||
Event("FixedUpdate", App.FixedUpdateLength, App.FixedUpdateDelegates);
|
||||
}
|
||||
|
||||
private void Event(string title, int length, Delegate[] delegates)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "Agoxandr.Utils.Editor",
|
||||
"name": "Shazbot.Utils.Editor",
|
||||
"rootNamespace": "Utils",
|
||||
"references": [
|
||||
"GUID:80ed647da8ce73c45b66c239eba0365a"
|
37
Runtime/App.cs
Normal file
37
Runtime/App.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
public static class App
|
||||
{
|
||||
public static event Action Update;
|
||||
public static event Action LateUpdate;
|
||||
public static event Action EarlyUpdate;
|
||||
public static event Action LastUpdate;
|
||||
public static event Action FixedUpdate;
|
||||
|
||||
internal static void InvokeUpdate() => Update?.Invoke();
|
||||
internal static void InvokeLateUpdate() => LateUpdate?.Invoke();
|
||||
internal static void InvokeEarlyUpdate() => EarlyUpdate?.Invoke();
|
||||
internal static void InvokeLastUpdate() => LastUpdate?.Invoke();
|
||||
internal static void InvokeFixedUpdate() => FixedUpdate?.Invoke();
|
||||
|
||||
internal static void ClearUpdate() => Update = null;
|
||||
internal static void ClearLateUpdate() => LateUpdate = null;
|
||||
internal static void ClearEarlyUpdate() => EarlyUpdate = null;
|
||||
internal static void ClearLastUpdate() => LastUpdate = null;
|
||||
internal static void ClearFixedUpdate() => FixedUpdate = null;
|
||||
|
||||
internal static Delegate[] UpdateDelegates => Update?.GetInvocationList();
|
||||
internal static Delegate[] LateUpdateDelegates => LateUpdate?.GetInvocationList();
|
||||
internal static Delegate[] EarlyUpdateDelegates => EarlyUpdate?.GetInvocationList();
|
||||
internal static Delegate[] LastUpdateDelegates => LastUpdate?.GetInvocationList();
|
||||
internal static Delegate[] FixedUpdateDelegates => FixedUpdate?.GetInvocationList();
|
||||
|
||||
internal static int UpdateLength => UpdateDelegates?.Length ?? 0;
|
||||
internal static int LateUpdateLength => LateUpdateDelegates?.Length ?? 0;
|
||||
internal static int EarlyUpdateLength => EarlyUpdateDelegates?.Length ?? 0;
|
||||
internal static int LastUpdateLength => LastUpdateDelegates?.Length ?? 0;
|
||||
internal static int FixedUpdateLength => FixedUpdateDelegates?.Length ?? 0;
|
||||
}
|
||||
}
|
3
Runtime/App.cs.meta
Normal file
3
Runtime/App.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c632d377fd764f02bdddbafa7f2b1fb5
|
||||
timeCreated: 1755398559
|
3
Runtime/AssemblyInfo.cs
Normal file
3
Runtime/AssemblyInfo.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Shazbot.Utils.Editor")]
|
3
Runtime/AssemblyInfo.cs.meta
Normal file
3
Runtime/AssemblyInfo.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35be5c971f104f92ba7001fac3ca91f9
|
||||
timeCreated: 1755401993
|
@@ -1,61 +1,27 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
public class EventManager : MonoBehaviour
|
||||
{
|
||||
public delegate void UpdateAction();
|
||||
|
||||
public static event UpdateAction Updated;
|
||||
|
||||
public delegate void LateUpdateAction();
|
||||
|
||||
public static event LateUpdateAction LateUpdated;
|
||||
|
||||
public delegate void EarlyUpdateAction();
|
||||
|
||||
public static event EarlyUpdateAction EarlyUpdated;
|
||||
|
||||
public delegate void LastUpdateAction();
|
||||
|
||||
public static event LastUpdateAction LastUpdated;
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
EarlyUpdated?.Invoke();
|
||||
Updated?.Invoke();
|
||||
App.InvokeEarlyUpdate();
|
||||
App.InvokeUpdate();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
LateUpdated?.Invoke();
|
||||
LastUpdated?.Invoke();
|
||||
App.InvokeLateUpdate();
|
||||
App.InvokeLastUpdate();
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
Updated = null;
|
||||
LateUpdated = null;
|
||||
EarlyUpdated = null;
|
||||
LastUpdated = null;
|
||||
}
|
||||
|
||||
public static Delegate[] EarlyUpdateDelegates => EarlyUpdated?.GetInvocationList();
|
||||
|
||||
public static int EarlyUpdateLength => EarlyUpdateDelegates?.Length ?? 0;
|
||||
|
||||
public static Delegate[] UpdateDelegates => Updated?.GetInvocationList();
|
||||
|
||||
public static int UpdateLength => UpdateDelegates?.Length ?? 0;
|
||||
|
||||
public static Delegate[] LateUpdateDelegates => LateUpdated?.GetInvocationList();
|
||||
|
||||
public static int LateUpdateLength => LateUpdateDelegates?.Length ?? 0;
|
||||
|
||||
public static Delegate[] LastUpdateDelegates => LastUpdated?.GetInvocationList();
|
||||
|
||||
public static int LastUpdateLength => LastUpdateDelegates?.Length ?? 0;
|
||||
App.ClearUpdate();
|
||||
App.ClearLateUpdate();
|
||||
App.ClearEarlyUpdate();
|
||||
App.ClearLastUpdate();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,26 +1,17 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
public class PhysicsEventManager : MonoBehaviour
|
||||
{
|
||||
public delegate void FixedUpdateAction();
|
||||
|
||||
public static event FixedUpdateAction FixedUpdated;
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
FixedUpdated?.Invoke();
|
||||
App.InvokeFixedUpdate();
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
FixedUpdated = null;
|
||||
}
|
||||
|
||||
public static Delegate[] FixedUpdateDelegates => FixedUpdated?.GetInvocationList();
|
||||
|
||||
public static int FixedUpdateLength => FixedUpdateDelegates?.Length ?? 0;
|
||||
App.ClearFixedUpdate();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "Agoxandr.Utils",
|
||||
"name": "Shazbot.Utils",
|
||||
"rootNamespace": "Utils",
|
||||
"references": [
|
||||
"GUID:1491147abca9d7d4bb7105af628b223e"
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ru.shazbot.utils",
|
||||
"version": "6.1.1",
|
||||
"version": "7.0.0",
|
||||
"displayName": "Utils",
|
||||
"description": "Utility useful for almost any project.",
|
||||
"licensesUrl": "https://git.shazbot.ru/shazbot/Utils/src/LICENSE.md",
|
||||
|
Reference in New Issue
Block a user