Added separate EventManger for FixedUpdate.

This commit is contained in:
Alexander Filippov 2024-04-23 14:03:38 +02:00
parent 6b0bb3de6b
commit 1ca24af85a
11 changed files with 85 additions and 37 deletions

View File

@ -2,10 +2,10 @@
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils.Editor
{ {
[CustomEditor(typeof(EventManager), true)] [CustomEditor(typeof(EventManager), true)]
public class EventManagerEditor : Editor public class EventManagerEditor : UnityEditor.Editor
{ {
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {

View File

@ -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);
}
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2dc65e2b44db4ae5ac60ad4ecf343e82
timeCreated: 1713873473

View File

@ -1,7 +1,7 @@
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils.Editor
{ {
[CustomPropertyDrawer(typeof(ReadOnlyFieldAttribute))] [CustomPropertyDrawer(typeof(ReadOnlyFieldAttribute))]
public class ReadOnlyFieldDrawer : PropertyDrawer public class ReadOnlyFieldDrawer : PropertyDrawer

View File

@ -1,7 +1,7 @@
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils.Editor
{ {
[CustomPropertyDrawer(typeof(ReadOnlyOnPlayFieldAttribute))] [CustomPropertyDrawer(typeof(ReadOnlyOnPlayFieldAttribute))]
public class ReadOnlyOnPlayFieldDrawer : PropertyDrawer public class ReadOnlyOnPlayFieldDrawer : PropertyDrawer

View File

@ -1,7 +1,7 @@
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils.Editor
{ {
[InitializeOnLoad] [InitializeOnLoad]
public static class SceneViewRotation public static class SceneViewRotation

View File

@ -12,11 +12,6 @@
"autoReferenced": true, "autoReferenced": true,
"defineConstraints": [], "defineConstraints": [],
"versionDefines": [ "versionDefines": [
{
"name": "com.unity.modules.physics",
"expression": "",
"define": "COM_UNITY_MODULES_PHYSICS"
},
{ {
"name": "com.unity.netcode.gameobjects", "name": "com.unity.netcode.gameobjects",
"expression": "", "expression": "",

View File

@ -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;
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c65e51916058437493fa66f8382a06c6
timeCreated: 1713872175

View File

@ -2,35 +2,27 @@ using UnityEngine;
namespace Utils namespace Utils
{ {
/// <summary>
/// https://garry.tv/timesince
/// </summary>
/// <example>
/// Do something after 10 seconds.
/// <code>
/// TimeSince ts;
/// void Start() => ts = 0;
/// void Update()
/// {
/// if (ts > 10)
/// Something();
/// }
/// </code>
/// </example>
public struct TimeSince public struct TimeSince
{ {
private float time; private float time;
public static implicit operator float(TimeSince ts) public static implicit operator float(TimeSince ts) => Time.time - ts.time;
{
return Time.time - ts.time;
}
public static implicit operator TimeSince(float ts) public static implicit operator TimeSince(float ts) => new() { time = Time.time - ts };
{
return new TimeSince { time = Time.time - ts };
}
} }
} }
// https://garry.tv/timesince
//TimeSince ts;
//void Start()
//{
// ts = 0;
//}
//void Update()
//{
// if (ts > 10)
// {
// DoSomethingAfterTenSeconds();
// }
//}

View File

@ -1,6 +1,6 @@
{ {
"name": "ru.shazbot.utils", "name": "ru.shazbot.utils",
"version": "6.0.0", "version": "6.1.0",
"displayName": "Utils", "displayName": "Utils",
"description": "Utility useful for almost any project.", "description": "Utility useful for almost any project.",
"licensesUrl": "https://git.shazbot.ru/Utils.git/tree/LICENSE.md", "licensesUrl": "https://git.shazbot.ru/Utils.git/tree/LICENSE.md",