From 7493a0cdcaa17e01c8a333bd7a5cee9f9d46d077 Mon Sep 17 00:00:00 2001 From: Alexander Filippov Date: Sun, 17 Aug 2025 06:43:30 +0200 Subject: [PATCH] Move events to App class. --- ...tor.asmdef => Shazbot.Utils.Editor.asmdef} | 2 +- ....meta => Shazbot.Utils.Editor.asmdef.meta} | 0 Runtime/App.cs | 37 +++++++++++++ Runtime/App.cs.meta | 3 ++ Runtime/AssemblyInfo.cs | 3 ++ Runtime/AssemblyInfo.cs.meta | 3 ++ Runtime/EventManager.cs | 52 ++++--------------- Runtime/PhysicsEventManager.cs | 13 +---- ...andr.Utils.asmdef => Shazbot.Utils.asmdef} | 2 +- ....asmdef.meta => Shazbot.Utils.asmdef.meta} | 0 package.json | 2 +- 11 files changed, 60 insertions(+), 57 deletions(-) rename Editor/{Agoxandr.Utils.Editor.asmdef => Shazbot.Utils.Editor.asmdef} (93%) rename Editor/{Agoxandr.Utils.Editor.asmdef.meta => Shazbot.Utils.Editor.asmdef.meta} (100%) create mode 100644 Runtime/App.cs create mode 100644 Runtime/App.cs.meta create mode 100644 Runtime/AssemblyInfo.cs create mode 100644 Runtime/AssemblyInfo.cs.meta rename Runtime/{Agoxandr.Utils.asmdef => Shazbot.Utils.asmdef} (94%) rename Runtime/{Agoxandr.Utils.asmdef.meta => Shazbot.Utils.asmdef.meta} (100%) diff --git a/Editor/Agoxandr.Utils.Editor.asmdef b/Editor/Shazbot.Utils.Editor.asmdef similarity index 93% rename from Editor/Agoxandr.Utils.Editor.asmdef rename to Editor/Shazbot.Utils.Editor.asmdef index b4fa70c..c3fa9e0 100644 --- a/Editor/Agoxandr.Utils.Editor.asmdef +++ b/Editor/Shazbot.Utils.Editor.asmdef @@ -1,5 +1,5 @@ { - "name": "Agoxandr.Utils.Editor", + "name": "Shazbot.Utils.Editor", "rootNamespace": "Utils", "references": [ "GUID:80ed647da8ce73c45b66c239eba0365a" diff --git a/Editor/Agoxandr.Utils.Editor.asmdef.meta b/Editor/Shazbot.Utils.Editor.asmdef.meta similarity index 100% rename from Editor/Agoxandr.Utils.Editor.asmdef.meta rename to Editor/Shazbot.Utils.Editor.asmdef.meta diff --git a/Runtime/App.cs b/Runtime/App.cs new file mode 100644 index 0000000..775c971 --- /dev/null +++ b/Runtime/App.cs @@ -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; + } +} \ No newline at end of file diff --git a/Runtime/App.cs.meta b/Runtime/App.cs.meta new file mode 100644 index 0000000..39b9ec5 --- /dev/null +++ b/Runtime/App.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c632d377fd764f02bdddbafa7f2b1fb5 +timeCreated: 1755398559 \ No newline at end of file diff --git a/Runtime/AssemblyInfo.cs b/Runtime/AssemblyInfo.cs new file mode 100644 index 0000000..d90cc9f --- /dev/null +++ b/Runtime/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Shazbot.Utils.Editor")] \ No newline at end of file diff --git a/Runtime/AssemblyInfo.cs.meta b/Runtime/AssemblyInfo.cs.meta new file mode 100644 index 0000000..44ec0b8 --- /dev/null +++ b/Runtime/AssemblyInfo.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 35be5c971f104f92ba7001fac3ca91f9 +timeCreated: 1755401993 \ No newline at end of file diff --git a/Runtime/EventManager.cs b/Runtime/EventManager.cs index 939947f..2ad8da9 100644 --- a/Runtime/EventManager.cs +++ b/Runtime/EventManager.cs @@ -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; } } \ No newline at end of file diff --git a/Runtime/PhysicsEventManager.cs b/Runtime/PhysicsEventManager.cs index 7b8faa5..5ee7ea2 100644 --- a/Runtime/PhysicsEventManager.cs +++ b/Runtime/PhysicsEventManager.cs @@ -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; } } \ No newline at end of file diff --git a/Runtime/Agoxandr.Utils.asmdef b/Runtime/Shazbot.Utils.asmdef similarity index 94% rename from Runtime/Agoxandr.Utils.asmdef rename to Runtime/Shazbot.Utils.asmdef index ff20cdf..6128432 100644 --- a/Runtime/Agoxandr.Utils.asmdef +++ b/Runtime/Shazbot.Utils.asmdef @@ -1,5 +1,5 @@ { - "name": "Agoxandr.Utils", + "name": "Shazbot.Utils", "rootNamespace": "Utils", "references": [ "GUID:1491147abca9d7d4bb7105af628b223e" diff --git a/Runtime/Agoxandr.Utils.asmdef.meta b/Runtime/Shazbot.Utils.asmdef.meta similarity index 100% rename from Runtime/Agoxandr.Utils.asmdef.meta rename to Runtime/Shazbot.Utils.asmdef.meta diff --git a/package.json b/package.json index a8d4f95..f68ca6a 100644 --- a/package.json +++ b/package.json @@ -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",