diff --git a/Editor/EventManagerEditor.cs b/Editor/EventManagerEditor.cs index 60af00c..1c0cb70 100644 --- a/Editor/EventManagerEditor.cs +++ b/Editor/EventManagerEditor.cs @@ -2,10 +2,10 @@ using UnityEditor; using UnityEngine; -namespace Utils +namespace Utils.Editor { [CustomEditor(typeof(EventManager), true)] - public class EventManagerEditor : Editor + public class EventManagerEditor : UnityEditor.Editor { public override void OnInspectorGUI() { diff --git a/Editor/PhysicsEventMangerEditor.cs b/Editor/PhysicsEventMangerEditor.cs new file mode 100644 index 0000000..e7640d4 --- /dev/null +++ b/Editor/PhysicsEventMangerEditor.cs @@ -0,0 +1,34 @@ +using System; +using UnityEditor; +using UnityEngine; + +namespace Utils.Editor +{ + [CustomEditor(typeof(PhysicsEventManager), true)] + public class PhysicsEventManagerEditor : UnityEditor.Editor + { + public override void OnInspectorGUI() + { + Event("FixedUpdate", PhysicsEventManager.FixedUpdateLength, PhysicsEventManager.FixedUpdateDelegates); + } + + private void Event(string title, int length, Delegate[] delegates) + { + { + GUILayout.BeginHorizontal(); + + GUILayout.Label(title, EditorStyles.boldLabel); + GUILayout.FlexibleSpace(); + 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); + } + } + } + } +} \ No newline at end of file diff --git a/Editor/PhysicsEventMangerEditor.cs.meta b/Editor/PhysicsEventMangerEditor.cs.meta new file mode 100644 index 0000000..e818718 --- /dev/null +++ b/Editor/PhysicsEventMangerEditor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2dc65e2b44db4ae5ac60ad4ecf343e82 +timeCreated: 1713873473 \ No newline at end of file diff --git a/Editor/ReadOnlyFieldDrawer.cs b/Editor/ReadOnlyFieldDrawer.cs index ea2e66d..7267e05 100644 --- a/Editor/ReadOnlyFieldDrawer.cs +++ b/Editor/ReadOnlyFieldDrawer.cs @@ -1,7 +1,7 @@ using UnityEditor; using UnityEngine; -namespace Utils +namespace Utils.Editor { [CustomPropertyDrawer(typeof(ReadOnlyFieldAttribute))] public class ReadOnlyFieldDrawer : PropertyDrawer diff --git a/Editor/ReadOnlyOnPlayFieldDrawer.cs b/Editor/ReadOnlyOnPlayFieldDrawer.cs index 3abe5e8..129771a 100644 --- a/Editor/ReadOnlyOnPlayFieldDrawer.cs +++ b/Editor/ReadOnlyOnPlayFieldDrawer.cs @@ -1,7 +1,7 @@ using UnityEditor; using UnityEngine; -namespace Utils +namespace Utils.Editor { [CustomPropertyDrawer(typeof(ReadOnlyOnPlayFieldAttribute))] public class ReadOnlyOnPlayFieldDrawer : PropertyDrawer diff --git a/Editor/SceneViewRotation.cs b/Editor/SceneViewRotation.cs index 069ddab..341df0c 100644 --- a/Editor/SceneViewRotation.cs +++ b/Editor/SceneViewRotation.cs @@ -1,7 +1,7 @@ using UnityEditor; using UnityEngine; -namespace Utils +namespace Utils.Editor { [InitializeOnLoad] public static class SceneViewRotation diff --git a/Runtime/Agoxandr.Utils.asmdef b/Runtime/Agoxandr.Utils.asmdef index e316633..ff20cdf 100644 --- a/Runtime/Agoxandr.Utils.asmdef +++ b/Runtime/Agoxandr.Utils.asmdef @@ -12,11 +12,6 @@ "autoReferenced": true, "defineConstraints": [], "versionDefines": [ - { - "name": "com.unity.modules.physics", - "expression": "", - "define": "COM_UNITY_MODULES_PHYSICS" - }, { "name": "com.unity.netcode.gameobjects", "expression": "", diff --git a/Runtime/PhysicsEventManager.cs b/Runtime/PhysicsEventManager.cs new file mode 100644 index 0000000..9381075 --- /dev/null +++ b/Runtime/PhysicsEventManager.cs @@ -0,0 +1,21 @@ +using System; +using UnityEngine; + +namespace Utils +{ + public class PhysicsEventManager : MonoBehaviour + { + public delegate void FixedUpdateAction(); + + public static event FixedUpdateAction FixedUpdated; + + private void FixedUpdate() + { + FixedUpdated?.Invoke(); + } + + public static Delegate[] FixedUpdateDelegates => FixedUpdated?.GetInvocationList(); + + public static int FixedUpdateLength => FixedUpdateDelegates?.Length ?? 0; + } +} \ No newline at end of file diff --git a/Runtime/PhysicsEventManager.cs.meta b/Runtime/PhysicsEventManager.cs.meta new file mode 100644 index 0000000..bbfd03c --- /dev/null +++ b/Runtime/PhysicsEventManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c65e51916058437493fa66f8382a06c6 +timeCreated: 1713872175 \ No newline at end of file diff --git a/Runtime/TimeSince.cs b/Runtime/TimeSince.cs index 1736d7a..8d7396e 100644 --- a/Runtime/TimeSince.cs +++ b/Runtime/TimeSince.cs @@ -2,35 +2,27 @@ using UnityEngine; namespace Utils { + /// + /// https://garry.tv/timesince + /// + /// + /// Do something after 10 seconds. + /// + /// TimeSince ts; + /// void Start() => ts = 0; + /// void Update() + /// { + /// if (ts > 10) + /// Something(); + /// } + /// + /// public struct TimeSince { private float time; - public static implicit operator float(TimeSince ts) - { - return Time.time - ts.time; - } + public static implicit operator float(TimeSince ts) => Time.time - ts.time; - public static implicit operator TimeSince(float ts) - { - return new TimeSince { time = Time.time - ts }; - } + public static implicit operator TimeSince(float ts) => new() { time = Time.time - ts }; } -} - -// https://garry.tv/timesince - -//TimeSince ts; - -//void Start() -//{ -// ts = 0; -//} - -//void Update() -//{ -// if (ts > 10) -// { -// DoSomethingAfterTenSeconds(); -// } -//} +} \ No newline at end of file diff --git a/package.json b/package.json index 213b296..abeb6c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ru.shazbot.utils", - "version": "6.0.0", + "version": "6.1.0", "displayName": "Utils", "description": "Utility useful for almost any project.", "licensesUrl": "https://git.shazbot.ru/Utils.git/tree/LICENSE.md",