From ac09b78edd4ca657820d684a47f2f009ac645244 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Fri, 26 Jan 2024 18:49:26 +0300 Subject: [PATCH] feat: Transform Recalculation Conditions Updated --- Engine.Physics2D/Collider2DBehaviourBase.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Engine.Physics2D/Collider2DBehaviourBase.cs b/Engine.Physics2D/Collider2DBehaviourBase.cs index 93becf7..061d557 100644 --- a/Engine.Physics2D/Collider2DBehaviourBase.cs +++ b/Engine.Physics2D/Collider2DBehaviourBase.cs @@ -39,13 +39,15 @@ public abstract class Collider2DBehaviourBase : BehaviourOverride, ICollider2D BehaviourController.OnBehaviourAdded += OnBehaviourAddedToController; BehaviourController.OnBehaviourRemoved += OnBehaviourRemovedFromController; - Transform.OnPositionChanged += OnPositionChanged; + Transform.OnPositionChanged += SetNeedsRecalculation; + Transform.OnRotationChanged += SetNeedsRecalculation; + Transform.OnScaleChanged += SetNeedsRecalculation; } private void OnBehaviourAddedToController(IBehaviourController _, IBehaviour behaviour) { - if (behaviour is IRigidBody2D rigidbody) - _rigidBody2D = rigidbody; + if (behaviour is IRigidBody2D rigidBody) + _rigidBody2D = rigidBody; } private void OnBehaviourRemovedFromController(IBehaviourController _, IBehaviour behaviour) @@ -54,13 +56,15 @@ public abstract class Collider2DBehaviourBase : BehaviourOverride, ICollider2D _rigidBody2D = null; } - private void OnPositionChanged(ITransform transform) => NeedsRecalculation = true; + private void SetNeedsRecalculation(ITransform transform) => NeedsRecalculation = true; protected override void OnFinalize() { BehaviourController.OnBehaviourAdded -= OnBehaviourAddedToController; BehaviourController.OnBehaviourRemoved -= OnBehaviourRemovedFromController; + Transform.OnScaleChanged -= SetNeedsRecalculation; - Transform.OnPositionChanged -= OnPositionChanged; + Transform.OnPositionChanged -= SetNeedsRecalculation; + Transform.OnRotationChanged -= SetNeedsRecalculation; } }