refactor: Replaced "Member" IStateEnable

This commit is contained in:
Syntriax 2023-03-20 22:51:19 +03:00
parent 25be6929f2
commit 0fc73f330b
2 changed files with 15 additions and 12 deletions

View File

@ -7,9 +7,9 @@ namespace Syntriax.Modules.Movement
public interface IMovementController
{
/// <summary>
/// Member <see cref="IStateEnable"/> to switch on or off
/// <see cref="IStateEnable"/> to control the state of the <see cref="IMovementController"/> is on or off
/// </summary>
IStateEnable StateEnableMember { get; }
IStateEnable StateEnable { get; }
/// <summary>
/// Currently active <see cref="IMovement"/>

View File

@ -31,13 +31,17 @@ namespace Syntriax.Modules.Movement
}
}
private bool areBothStateEnablesToggled => StateEnableMember.IsEnabledNullChecked() && stateEnableOnGameObject.IsEnabledNullChecked();
public List<IMovement> Movements { get; protected set; } = new List<IMovement>(32);
public IStateEnable StateEnableMember { get; protected set; } = new StateEnableMember(true);
protected IStateEnable stateEnableOnGameObject = null;
private IStateEnable _stateEnable = null;
public IStateEnable StateEnable
{
get
{
_stateEnable = _stateEnable ?? GetComponent<State.IStateEnable>() ?? gameObject.AddComponent<State.StateEnableMonoBehaviour>();
return _stateEnable;
}
}
protected virtual void Start()
{
@ -45,16 +49,14 @@ namespace Syntriax.Modules.Movement
gameObject.AddComponent<DefaultMovement>();
RecacheMovements();
stateEnableOnGameObject = GetComponent<IStateEnable>();
stateEnableOnGameObject.OnEnabledChanged += (_) => InvokeOnMoveAction();
StateEnableMember.OnEnabledChanged += (_) => InvokeOnMoveAction();
StateEnable.OnEnabledChanged += (_) => InvokeOnMoveAction();
OnMovementActivated += (newMovement) => newMovement.Move(lastMove);
}
protected virtual void FixedUpdate()
{
if (!areBothStateEnablesToggled)
if (!StateEnable.IsEnabledNullChecked())
return;
ActiveMovement?.ApplyMovement();
@ -86,6 +88,7 @@ namespace Syntriax.Modules.Movement
}
private Vector3 lastMove = Vector3.zero;
public void Move(float x = 0, float y = 0, float z = 0)
{
ActiveMovement?.Move(x, y, z);
@ -96,7 +99,7 @@ namespace Syntriax.Modules.Movement
private void InvokeOnMoveAction()
{
if (!areBothStateEnablesToggled)
if (!StateEnable.IsEnabledNullChecked())
return;
OnMoveCalled?.Invoke(lastMove.x, lastMove.y, lastMove.z);