feat(core): IBehavior.IsActive
This commit is contained in:
parent
dc96b93024
commit
1c7d941bc1
|
@ -16,4 +16,9 @@ public interface IBehaviour : IEntity, IAssignableBehaviourController, IAssignab
|
|||
/// Call priority of the <see cref="IBehaviour"/>.
|
||||
/// </summary>
|
||||
int Priority { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If the <see cref="IBehaviour"/> is active.
|
||||
/// </summary>
|
||||
bool IsActive { get; }
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ public abstract class Behaviour : IBehaviour
|
|||
public IStateEnable StateEnable => _stateEnable;
|
||||
public IBehaviourController BehaviourController => _behaviourController;
|
||||
|
||||
public bool IsActive => StateEnable.Enabled && BehaviourController.GameObject.StateEnable.Enabled;
|
||||
|
||||
public bool Initialized
|
||||
{
|
||||
get => _initialized;
|
||||
|
|
|
@ -39,13 +39,13 @@ public abstract class BehaviourOverride : Behaviour
|
|||
OnFinalize();
|
||||
}
|
||||
|
||||
protected virtual void OnPreUpdatePreEnabledCheck() { }
|
||||
protected virtual void OnPreUpdatePreActiveCheck() { }
|
||||
protected virtual void OnPreUpdate() { }
|
||||
private void PreUpdate(IBehaviourController _)
|
||||
{
|
||||
OnPreUpdatePreEnabledCheck();
|
||||
OnPreUpdatePreActiveCheck();
|
||||
|
||||
if (!StateEnable.Enabled)
|
||||
if (!IsActive)
|
||||
return;
|
||||
|
||||
if (isInitializedThisFrame)
|
||||
|
@ -61,23 +61,23 @@ public abstract class BehaviourOverride : Behaviour
|
|||
isInitializedThisFrame = false;
|
||||
}
|
||||
|
||||
protected virtual void OnUpdatePreEnabledCheck() { }
|
||||
protected virtual void OnUpdatePreActiveCheck() { }
|
||||
protected virtual void OnUpdate() { }
|
||||
private void Update(IBehaviourController _)
|
||||
{
|
||||
OnUpdatePreEnabledCheck();
|
||||
OnUpdatePreActiveCheck();
|
||||
|
||||
if (!StateEnable.Enabled)
|
||||
if (!IsActive)
|
||||
return;
|
||||
|
||||
OnUpdate();
|
||||
}
|
||||
|
||||
protected virtual void OnPreDrawPreEnabledCheck() { }
|
||||
protected virtual void OnPreDrawPreActiveCheck() { }
|
||||
protected virtual void OnPreDraw() { }
|
||||
private void PreDraw(IBehaviourController _)
|
||||
{
|
||||
OnPreDrawPreEnabledCheck();
|
||||
OnPreDrawPreActiveCheck();
|
||||
|
||||
if (!StateEnable.Enabled)
|
||||
return;
|
||||
|
|
|
@ -54,10 +54,16 @@ public class PhysicsEngine2D : IPhysicsEngine2D
|
|||
for (int x = 0; x < colliders.Count; x++)
|
||||
{
|
||||
ICollider2D? colliderX = colliders[x];
|
||||
if (!colliderX.IsActive)
|
||||
return;
|
||||
|
||||
for (int y = x + 1; y < colliders.Count; y++)
|
||||
{
|
||||
ICollider2D? colliderY = colliders[y];
|
||||
|
||||
if (!colliderY.IsActive)
|
||||
return;
|
||||
|
||||
if (colliderX.RigidBody2D == colliderY.RigidBody2D)
|
||||
continue;
|
||||
|
||||
|
|
Loading…
Reference in New Issue