Move events to App class.

This commit is contained in:
2025-08-17 06:43:30 +02:00
parent dbac051fc2
commit 7493a0cdca
11 changed files with 60 additions and 57 deletions

View File

@@ -1,5 +1,5 @@
{
"name": "Agoxandr.Utils.Editor",
"name": "Shazbot.Utils.Editor",
"rootNamespace": "Utils",
"references": [
"GUID:80ed647da8ce73c45b66c239eba0365a"

37
Runtime/App.cs Normal file
View 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
View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c632d377fd764f02bdddbafa7f2b1fb5
timeCreated: 1755398559

3
Runtime/AssemblyInfo.cs Normal file
View File

@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Shazbot.Utils.Editor")]

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 35be5c971f104f92ba7001fac3ca91f9
timeCreated: 1755401993

View File

@@ -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;
App.ClearUpdate();
App.ClearLateUpdate();
App.ClearEarlyUpdate();
App.ClearLastUpdate();
}
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;
}
}

View File

@@ -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;
App.ClearFixedUpdate();
}
public static Delegate[] FixedUpdateDelegates => FixedUpdated?.GetInvocationList();
public static int FixedUpdateLength => FixedUpdateDelegates?.Length ?? 0;
}
}

View File

@@ -1,5 +1,5 @@
{
"name": "Agoxandr.Utils",
"name": "Shazbot.Utils",
"rootNamespace": "Utils",
"references": [
"GUID:1491147abca9d7d4bb7105af628b223e"

View File

@@ -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",