Improved OnMoveCalled on MovementController
This commit is contained in:
parent
fc22863f57
commit
70edb0e5a1
|
@ -31,6 +31,8 @@ namespace Syntriax.Modules.Movement
|
|||
}
|
||||
}
|
||||
|
||||
private bool areBothToggleStatesToggled => ToggleState.IsToggledNullChecked() && toggleStateOnGameObject.IsToggledNullChecked();
|
||||
|
||||
public List<IMovement> Movements { get; protected set; } = new List<IMovement>(32);
|
||||
|
||||
public IToggleState ToggleState { get; protected set; } = new ToggleStateMember(true);
|
||||
|
@ -44,11 +46,14 @@ namespace Syntriax.Modules.Movement
|
|||
|
||||
RecacheMovements();
|
||||
toggleStateOnGameObject = GetComponent<IToggleState>();
|
||||
|
||||
toggleStateOnGameObject.OnToggleStateChanged += (_) => InvokeOnMoveAction();
|
||||
ToggleState.OnToggleStateChanged += (_) => InvokeOnMoveAction();
|
||||
}
|
||||
|
||||
protected virtual void FixedUpdate()
|
||||
{
|
||||
if (!ToggleState.IsToggledNullChecked() || !toggleStateOnGameObject.IsToggledNullChecked())
|
||||
if (!areBothToggleStatesToggled)
|
||||
return;
|
||||
|
||||
ActiveMovement?.ApplyMovement();
|
||||
|
@ -79,10 +84,21 @@ 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);
|
||||
OnMoveCalled?.Invoke(x, y, z);
|
||||
(lastMove.x, lastMove.y, lastMove.z) = (x, y, z);
|
||||
|
||||
InvokeOnMoveAction();
|
||||
}
|
||||
|
||||
private void InvokeOnMoveAction()
|
||||
{
|
||||
if (!areBothToggleStatesToggled)
|
||||
return;
|
||||
|
||||
OnMoveCalled?.Invoke(lastMove.x, lastMove.y, lastMove.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue