fix: Collider2D Not Registering Rigidbody2D Attached

This commit is contained in:
Syntriax 2024-01-25 21:52:56 +03:00
parent 3b83be695c
commit e7ca96e2e2
1 changed files with 25 additions and 1 deletions

View File

@ -23,5 +23,29 @@ public abstract class Collider2DBehaviourBase : BehaviourOverride, ICollider2D
public abstract void Recalculate(); public abstract void Recalculate();
protected override void OnInitialize() => BehaviourController.TryGetBehaviour(out _rigidBody2D); protected override void OnInitialize()
{
BehaviourController.TryGetBehaviour(out _rigidBody2D);
BehaviourController.OnBehaviourAdded += OnBehaviourAddedToController;
BehaviourController.OnBehaviourRemoved += OnBehaviourRemovedFromController;
}
private void OnBehaviourAddedToController(IBehaviourController _, IBehaviour behaviour)
{
if (behaviour is IRigidBody2D rigidbody)
_rigidBody2D = rigidbody;
}
private void OnBehaviourRemovedFromController(IBehaviourController _, IBehaviour behaviour)
{
if (behaviour is IRigidBody2D _)
_rigidBody2D = null;
}
protected override void OnFinalize()
{
BehaviourController.OnBehaviourAdded -= OnBehaviourAddedToController;
BehaviourController.OnBehaviourRemoved -= OnBehaviourRemovedFromController; ;
}
} }