refactor!: IGameObject removed
This commit is contained in:
@@ -5,7 +5,7 @@ namespace Syntriax.Engine.Physics2D.Abstract;
|
||||
/// <summary>
|
||||
/// Represents a 2D collider.
|
||||
/// </summary>
|
||||
public interface ICollider2D : IBehaviour, IAssignableTransform
|
||||
public interface ICollider2D : IBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Event triggered when a collision is detected.
|
||||
@@ -22,6 +22,9 @@ public interface ICollider2D : IBehaviour, IAssignableTransform
|
||||
/// </summary>
|
||||
event OnTriggeredEventHandler? OnTriggered;
|
||||
|
||||
/// <inheritdoc cref="ITransform2D" />
|
||||
ITransform2D Transform { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IRigidBody2D"/> associated with the <see cref="ICollider2D"/>.
|
||||
/// </summary>
|
||||
|
@@ -6,7 +6,7 @@ namespace Syntriax.Engine.Physics2D.Abstract;
|
||||
/// <summary>
|
||||
/// Represents a 2D rigid body in the engine.
|
||||
/// </summary>
|
||||
public interface IRigidBody2D : IBehaviour, IAssignableTransform
|
||||
public interface IRigidBody2D : IBehaviour2D
|
||||
{
|
||||
/// <summary>
|
||||
/// The physics material of the <see cref="IRigidBody2D"/>.
|
||||
|
@@ -4,7 +4,7 @@ using Syntriax.Engine.Physics2D.Abstract;
|
||||
|
||||
namespace Syntriax.Engine.Physics2D;
|
||||
|
||||
public abstract class Collider2DBehaviourBase : Behaviour, ICollider2D
|
||||
public abstract class Collider2DBehaviourBase : Behaviour2D, ICollider2D
|
||||
{
|
||||
public event ICollider2D.OnCollisionDetectedEventHandler? OnCollisionDetected = null;
|
||||
public event ICollider2D.OnCollisionResolvedEventHandler? OnCollisionResolved = null;
|
||||
@@ -16,11 +16,6 @@ public abstract class Collider2DBehaviourBase : Behaviour, ICollider2D
|
||||
public IRigidBody2D? RigidBody2D => _rigidBody2D;
|
||||
public bool IsTrigger { get; set; } = false;
|
||||
|
||||
ITransform IAssignableTransform.Transform => Transform;
|
||||
public event IAssignableTransform.OnTransformAssignedEventHandler? OnTransformAssigned { add => GameObject.OnTransformAssigned += value; remove => GameObject.OnTransformAssigned -= value; }
|
||||
|
||||
bool IAssignableTransform.Assign(ITransform transform) => GameObject.Assign(transform);
|
||||
|
||||
public void Recalculate()
|
||||
{
|
||||
if (!NeedsRecalculation)
|
||||
@@ -42,10 +37,10 @@ public abstract class Collider2DBehaviourBase : Behaviour, ICollider2D
|
||||
Transform.OnPositionChanged += SetNeedsRecalculationFromPosition;
|
||||
Transform.OnRotationChanged += SetNeedsRecalculationFromRotation;
|
||||
Transform.OnScaleChanged += SetNeedsRecalculationFromScale;
|
||||
Transform.OnParentChanged += UpdateRigidBody2D;
|
||||
HierarchyObject.OnParentChanged += UpdateRigidBody2D;
|
||||
}
|
||||
|
||||
private void UpdateRigidBody2D(ITransform sender, ITransform? previousParent, ITransform? newParent)
|
||||
private void UpdateRigidBody2D(IHierarchyObject sender, IHierarchyObject? previousParent, IHierarchyObject? newParent)
|
||||
{
|
||||
BehaviourController.TryGetBehaviourInParent(out _rigidBody2D);
|
||||
}
|
||||
@@ -62,9 +57,9 @@ public abstract class Collider2DBehaviourBase : Behaviour, ICollider2D
|
||||
_rigidBody2D = null;
|
||||
}
|
||||
|
||||
private void SetNeedsRecalculationFromScale(ITransform sender, Vector2D previousScale) => NeedsRecalculation = true;
|
||||
private void SetNeedsRecalculationFromPosition(ITransform sender, Vector2D previousPosition) => NeedsRecalculation = true;
|
||||
private void SetNeedsRecalculationFromRotation(ITransform sender, float previousRotation) => NeedsRecalculation = true;
|
||||
private void SetNeedsRecalculationFromScale(ITransform2D sender, Vector2D previousScale) => NeedsRecalculation = true;
|
||||
private void SetNeedsRecalculationFromPosition(ITransform2D sender, Vector2D previousPosition) => NeedsRecalculation = true;
|
||||
private void SetNeedsRecalculationFromRotation(ITransform2D sender, float previousRotation) => NeedsRecalculation = true;
|
||||
|
||||
protected override void OnFinalize()
|
||||
{
|
||||
|
@@ -7,7 +7,7 @@ using Syntriax.Engine.Physics2D.Abstract;
|
||||
|
||||
namespace Syntriax.Engine.Physics2D;
|
||||
|
||||
public class PhysicsCoroutineManager : HierarchyObjectBase
|
||||
public class PhysicsCoroutineManager : HierarchyObject
|
||||
{
|
||||
private readonly List<IEnumerator> enumerators = [];
|
||||
private IPhysicsEngine2D? physicsEngine = null;
|
||||
|
@@ -4,7 +4,7 @@ using Syntriax.Engine.Physics2D.Abstract;
|
||||
|
||||
namespace Syntriax.Engine.Physics2D;
|
||||
|
||||
public class PhysicsEngine2DCollector : HierarchyObjectBase, IPhysicsEngine2D
|
||||
public class PhysicsEngine2DCollector : HierarchyObject, IPhysicsEngine2D
|
||||
{
|
||||
public event IPhysicsEngine2D.OnPhysicsIterationEventHandler? OnPhysicsIteration = null;
|
||||
public event IPhysicsEngine2D.OnPhysicsStepEventHandler? OnPhysicsStep = null;
|
||||
|
@@ -1,13 +1,10 @@
|
||||
using Syntriax.Engine.Core;
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
using Syntriax.Engine.Physics2D.Abstract;
|
||||
|
||||
namespace Syntriax.Engine.Physics2D;
|
||||
|
||||
public class RigidBody2D : Behaviour, IRigidBody2D
|
||||
public class RigidBody2D : Behaviour2D, IRigidBody2D
|
||||
{
|
||||
event IAssignableTransform.OnTransformAssignedEventHandler? IAssignableTransform.OnTransformAssigned { add => GameObject.OnTransformAssigned += value; remove => GameObject.OnTransformAssigned -= value; }
|
||||
|
||||
private const float LOWEST_ALLOWED_MASS = 0.00001f;
|
||||
private float _mass = 1f;
|
||||
|
||||
@@ -18,8 +15,4 @@ public class RigidBody2D : Behaviour, IRigidBody2D
|
||||
public bool IsStatic { get; set; } = false;
|
||||
|
||||
public float Mass { get => _mass; set => _mass = Core.Math.Max(value, LOWEST_ALLOWED_MASS); }
|
||||
|
||||
ITransform IAssignableTransform.Transform => Transform;
|
||||
|
||||
public bool Assign(ITransform transform) => GameObject.Assign(transform);
|
||||
}
|
||||
|
Reference in New Issue
Block a user