fix: Collider2D Not Registering Rigidbody2D Attached
This commit is contained in:
parent
3b83be695c
commit
e7ca96e2e2
|
@ -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; ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue