Added separate EventManger for FixedUpdate.

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

View File

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

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
{
/// <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
{
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();
// }
//}
}