feat: Collider RigidBody Reference Update on Parent Change

This commit is contained in:
Syntriax 2024-02-06 12:26:14 +03:00
parent 3902f1caca
commit d9660c08b1
1 changed files with 7 additions and 1 deletions

View File

@ -37,7 +37,7 @@ public abstract class Collider2DBehaviourBase : BehaviourOverride, ICollider2D
protected override void OnInitialize() protected override void OnInitialize()
{ {
BehaviourController.TryGetBehaviour(out _rigidBody2D); BehaviourController.TryGetBehaviourInParent(out _rigidBody2D);
BehaviourController.OnBehaviourAdded += OnBehaviourAddedToController; BehaviourController.OnBehaviourAdded += OnBehaviourAddedToController;
BehaviourController.OnBehaviourRemoved += OnBehaviourRemovedFromController; BehaviourController.OnBehaviourRemoved += OnBehaviourRemovedFromController;
@ -45,6 +45,12 @@ public abstract class Collider2DBehaviourBase : BehaviourOverride, ICollider2D
Transform.OnPositionChanged += SetNeedsRecalculation; Transform.OnPositionChanged += SetNeedsRecalculation;
Transform.OnRotationChanged += SetNeedsRecalculation; Transform.OnRotationChanged += SetNeedsRecalculation;
Transform.OnScaleChanged += SetNeedsRecalculation; Transform.OnScaleChanged += SetNeedsRecalculation;
Transform.OnParentChanged += UpdateRigidBody2D;
}
private void UpdateRigidBody2D(ITransform _1, ITransform? _2)
{
BehaviourController.TryGetBehaviourInParent(out _rigidBody2D);
} }
private void OnBehaviourAddedToController(IBehaviourController _, IBehaviour behaviour) private void OnBehaviourAddedToController(IBehaviourController _, IBehaviour behaviour)