diff --git a/Editor/EventManagerEditor.cs b/Editor/EventManagerEditor.cs index e850bb9..60af00c 100644 --- a/Editor/EventManagerEditor.cs +++ b/Editor/EventManagerEditor.cs @@ -1,4 +1,5 @@ -using UnityEditor; +using System; +using UnityEditor; using UnityEngine; namespace Utils @@ -8,39 +9,32 @@ namespace Utils { public override void OnInspectorGUI() { - var eventManager = (EventManager)target; - GUILayout.BeginHorizontal(); - GUILayout.Label("Update"); - if (Application.isPlaying) + Event("EarlyUpdate", EventManager.EarlyUpdateLength, EventManager.EarlyUpdateDelegates); + EditorGUILayout.Space(); + Event("Update", EventManager.UpdateLength, EventManager.UpdateDelegates); + EditorGUILayout.Space(); + Event("LateUpdate", EventManager.LateUpdateLength, EventManager.LateUpdateDelegates); + EditorGUILayout.Space(); + Event("LastUpdate", EventManager.LastUpdateLength, EventManager.LastUpdateDelegates); + } + + private void Event(string title, int length, Delegate[] delegates) + { { + GUILayout.BeginHorizontal(); + + GUILayout.Label(title, EditorStyles.boldLabel); GUILayout.FlexibleSpace(); - GUILayout.Label(EventManager.UpdateLength.ToString()); + GUILayout.Label(length.ToString()); + + GUILayout.EndHorizontal(); + + if (length == 0) return; + foreach (var d in delegates) + { + GUILayout.Label($"{d.Method.DeclaringType}.{d.Method.Name}", EditorStyles.miniLabel); + } } - GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(); - GUILayout.Label("FixedUpdate"); - if (Application.isPlaying) - { - GUILayout.FlexibleSpace(); - GUILayout.Label(EventManager.FixedUpdateLength.ToString()); - } - GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(); - GUILayout.Label("LateUpdate"); - if (Application.isPlaying) - { - GUILayout.FlexibleSpace(); - GUILayout.Label(EventManager.LateUpdateLength.ToString()); - } - GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(); - GUILayout.Label("EarlyUpdate"); - if (Application.isPlaying) - { - GUILayout.FlexibleSpace(); - GUILayout.Label(EventManager.EarlyUpdateLength.ToString()); - } - GUILayout.EndHorizontal(); } } -} +} \ No newline at end of file diff --git a/Runtime/EventManager.cs b/Runtime/EventManager.cs index 7eebbc0..0a077dc 100644 --- a/Runtime/EventManager.cs +++ b/Runtime/EventManager.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System; +using UnityEngine; namespace Utils { @@ -8,10 +9,6 @@ namespace Utils public static event UpdateAction Updated; - public delegate void FixedUpdateAction(); - - public static event FixedUpdateAction FixedUpdated; - public delegate void LateUpdateAction(); public static event LateUpdateAction LateUpdated; @@ -31,60 +28,26 @@ namespace Utils Updated?.Invoke(); } - private void FixedUpdate() - { - FixedUpdated?.Invoke(); - } - private void LateUpdate() { LateUpdated?.Invoke(); LastUpdated?.Invoke(); } - public static int UpdateLength - { - get - { - var list = Updated?.GetInvocationList(); - return list?.Length ?? 0; - } - } + public static Delegate[] EarlyUpdateDelegates => EarlyUpdated?.GetInvocationList(); - public static int FixedUpdateLength - { - get - { - var list = FixedUpdated?.GetInvocationList(); - return list?.Length ?? 0; - } - } + public static int EarlyUpdateLength => EarlyUpdateDelegates?.Length ?? 0; - public static int LateUpdateLength - { - get - { - var list = LateUpdated?.GetInvocationList(); - return list?.Length ?? 0; - } - } + public static Delegate[] UpdateDelegates => Updated?.GetInvocationList(); - public static int EarlyUpdateLength - { - get - { - var list = EarlyUpdated?.GetInvocationList(); - return list?.Length ?? 0; - } - } + public static int UpdateLength => UpdateDelegates?.Length ?? 0; - public static int LastUpdateLength - { - get - { - var list = LastUpdated?.GetInvocationList(); - return list?.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/package.json b/package.json index b8c19fc..213b296 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ru.shazbot.utils", - "version": "5.2.0", + "version": "6.0.0", "displayName": "Utils", "description": "Utility useful for almost any project.", "licensesUrl": "https://git.shazbot.ru/Utils.git/tree/LICENSE.md",