refactor: updated systems to use the update interfaces
This commit is contained in:
@@ -5,7 +5,7 @@ using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Physics2D;
|
||||
|
||||
public class PhysicsCoroutineManager : Behaviour
|
||||
public class PhysicsCoroutineManager : Behaviour, IPhysicsUpdate
|
||||
{
|
||||
private readonly Event<IUniverse, IUniverse.UpdateArguments>.EventHandler delegateOnUpdate = null!;
|
||||
|
||||
@@ -23,16 +23,7 @@ public class PhysicsCoroutineManager : Behaviour
|
||||
enumerators.Remove(enumerator);
|
||||
}
|
||||
|
||||
protected override void OnEnteredUniverse(IUniverse universe)
|
||||
{
|
||||
physicsEngine = universe.FindRequiredBehaviour<IPhysicsEngine2D>();
|
||||
if (physicsEngine is IPhysicsEngine2D foundPhysicsEngine)
|
||||
foundPhysicsEngine.OnPhysicsStep.RemoveListener(OnPhysicsStep);
|
||||
else
|
||||
universe.OnUpdate.AddListener(OnUpdate);
|
||||
}
|
||||
|
||||
private void OnPhysicsStep(IPhysicsEngine2D sender, float stepDeltaTime)
|
||||
public void PhysicsUpdate(float delta)
|
||||
{
|
||||
for (int i = enumerators.Count - 1; i >= 0; i--)
|
||||
{
|
||||
@@ -44,28 +35,5 @@ public class PhysicsCoroutineManager : Behaviour
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnExitedUniverse(IUniverse universe)
|
||||
{
|
||||
if (physicsEngine is IPhysicsEngine2D existingPhysicsEngine)
|
||||
existingPhysicsEngine.OnPhysicsStep.RemoveListener(OnPhysicsStep);
|
||||
universe.OnUpdate.RemoveListener(delegateOnUpdate);
|
||||
}
|
||||
|
||||
private void OnUpdate(IUniverse sender, IUniverse.UpdateArguments args)
|
||||
{
|
||||
if (Universe is not IUniverse universe)
|
||||
return;
|
||||
|
||||
physicsEngine = universe.FindRequiredBehaviour<IPhysicsEngine2D>();
|
||||
if (physicsEngine is IPhysicsEngine2D foundPhysicsEngine)
|
||||
{
|
||||
foundPhysicsEngine.OnPhysicsStep.AddListener(OnPhysicsStep);
|
||||
universe.OnUpdate.RemoveListener(delegateOnUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
public PhysicsCoroutineManager()
|
||||
{
|
||||
delegateOnUpdate = OnUpdate;
|
||||
}
|
||||
public PhysicsCoroutineManager() => Priority = int.MinValue;
|
||||
}
|
||||
|
Reference in New Issue
Block a user