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