Amend Me
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
[System.Diagnostics.DebuggerDisplay("{GetType().Name, nq}, Priority: {Priority}, Initialized: {Initialized}")]
|
||||
public abstract class BehaviourBase : BaseEntity, IBehaviour
|
||||
{
|
||||
public Event<IBehaviour, int> OnPriorityChanged { get; private set; } = new();
|
||||
public Event<IActive, bool> OnActiveChanged { get; private set; } = new();
|
||||
public Event<IHasBehaviourController> OnBehaviourControllerAssigned { get; private set; } = new();
|
||||
public Event<IBehaviour, IBehaviour.PriorityChangedArguments> OnPriorityChanged { get; init; } = new();
|
||||
public Event<IActive, IActive.ActiveChangedArguments> OnActiveChanged { get; init; } = new();
|
||||
public Event<IHasBehaviourController> OnBehaviourControllerAssigned { get; init; } = new();
|
||||
|
||||
private Action<IHasUniverseObject> cachedOnUniverseObjectAssigned = null!;
|
||||
private Action<IActive, bool> cachedOnUniverseObjectActiveChanged = null!;
|
||||
private Action<IStateEnable, bool> cachedOnStateEnabledChanged = null!;
|
||||
private readonly Event<IHasUniverseObject>.EventHandler cachedOnUniverseObjectAssigned = null!;
|
||||
private readonly Event<IActive, IActive.ActiveChangedArguments>.EventHandler cachedOnUniverseObjectActiveChanged = null!;
|
||||
private readonly Event<IStateEnable, IStateEnable.EnabledChangedArguments>.EventHandler cachedOnStateEnabledChanged = null!;
|
||||
|
||||
private IBehaviourController _behaviourController = null!;
|
||||
public IBehaviourController BehaviourController => _behaviourController;
|
||||
@@ -27,7 +25,7 @@ public abstract class BehaviourBase : BaseEntity, IBehaviour
|
||||
|
||||
int previousPriority = _priority;
|
||||
_priority = value;
|
||||
OnPriorityChanged?.Invoke(this, previousPriority);
|
||||
OnPriorityChanged?.Invoke(this, new(previousPriority));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,8 +75,8 @@ public abstract class BehaviourBase : BaseEntity, IBehaviour
|
||||
Debug.Assert.AssertStateEnableAssigned(this);
|
||||
}
|
||||
|
||||
private void OnStateEnabledChanged(IStateEnable sender, bool previousState) => UpdateActive();
|
||||
private void OnUniverseObjectActiveChanged(IActive sender, bool previousState) => UpdateActive();
|
||||
private void OnStateEnabledChanged(IStateEnable sender, IStateEnable.EnabledChangedArguments arguments) => UpdateActive();
|
||||
private void OnUniverseObjectActiveChanged(IActive sender, IActive.ActiveChangedArguments arguments) => UpdateActive();
|
||||
|
||||
private void UpdateActive()
|
||||
{
|
||||
@@ -86,7 +84,7 @@ public abstract class BehaviourBase : BaseEntity, IBehaviour
|
||||
_isActive = StateEnable.Enabled && _behaviourController.UniverseObject.IsActive;
|
||||
|
||||
if (previousActive != IsActive)
|
||||
OnActiveChanged?.Invoke(this, previousActive);
|
||||
OnActiveChanged?.Invoke(this, new(previousActive));
|
||||
}
|
||||
|
||||
protected BehaviourBase()
|
||||
|
||||
Reference in New Issue
Block a user