feat: safe delegate invocation helper added
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.StateMachine;
|
||||
|
||||
public class State : IState
|
||||
@@ -35,12 +37,12 @@ public class State : IState
|
||||
public void Update()
|
||||
{
|
||||
if (GetNextState() is IState transitionState)
|
||||
OnStateTransitionReady?.Invoke(this, transitionState);
|
||||
OnStateUpdate?.Invoke(this);
|
||||
OnStateTransitionReady?.InvokeSafe(this, transitionState);
|
||||
OnStateUpdate?.InvokeSafe(this);
|
||||
}
|
||||
|
||||
public void TransitionTo(IState from) => OnStateTransitionedTo?.Invoke(this, from);
|
||||
public void TransitionFrom(IState to) => OnStateTransitionedFrom?.Invoke(this, to);
|
||||
public void TransitionTo(IState from) => OnStateTransitionedTo?.InvokeSafe(this, from);
|
||||
public void TransitionFrom(IState to) => OnStateTransitionedFrom?.InvokeSafe(this, to);
|
||||
|
||||
public IState? GetNextState()
|
||||
{
|
||||
|
@@ -16,21 +16,21 @@ public abstract class StateBehaviourBase : Behaviour, IState
|
||||
public void Update()
|
||||
{
|
||||
OnUpdateState();
|
||||
OnStateUpdate?.Invoke(this);
|
||||
OnStateUpdate?.InvokeSafe(this);
|
||||
}
|
||||
|
||||
protected virtual void OnTransitionedToState(IState from) { }
|
||||
public void TransitionTo(IState from)
|
||||
{
|
||||
OnTransitionedToState(from);
|
||||
OnStateTransitionedTo?.Invoke(this, from);
|
||||
OnStateTransitionedTo?.InvokeSafe(this, from);
|
||||
}
|
||||
|
||||
protected virtual void OnTransitionedFromState(IState to) { }
|
||||
public void TransitionFrom(IState to)
|
||||
{
|
||||
OnTransitionedFromState(to);
|
||||
OnStateTransitionedFrom?.Invoke(this, to);
|
||||
OnStateTransitionedFrom?.InvokeSafe(this, to);
|
||||
}
|
||||
|
||||
public abstract IState? GetNextState();
|
||||
|
@@ -21,7 +21,7 @@ public class StateMachine : Behaviour
|
||||
_state = value;
|
||||
previousState.TransitionFrom(value);
|
||||
value.TransitionTo(_state);
|
||||
OnStateChanged?.Invoke(this, previousState, value);
|
||||
OnStateChanged?.InvokeSafe(this, previousState, value);
|
||||
|
||||
value.OnStateTransitionReady += OnStateTransitionReady;
|
||||
}
|
||||
|
Reference in New Issue
Block a user