feat: added basic state machine system & Engine.Systems class library
This commit is contained in:
37
Engine.Systems/StateMachine/StateBehaviourBase.cs
Normal file
37
Engine.Systems/StateMachine/StateBehaviourBase.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.StateMachine;
|
||||
|
||||
public abstract class StateBehaviourBase : Behaviour, IState
|
||||
{
|
||||
public event IState.StateUpdateEventHandler? OnStateUpdate = null;
|
||||
public event IState.StateTransitionedFromEventHandler? OnStateTransitionedFrom = null;
|
||||
public event IState.StateTransitionedToEventHandler? OnStateTransitionedTo = null;
|
||||
|
||||
public abstract event IState.StateTransitionReadyEventHandler? OnStateTransitionReady;
|
||||
|
||||
public abstract string Name { get; }
|
||||
|
||||
protected virtual void OnUpdateState() { }
|
||||
public void Update()
|
||||
{
|
||||
OnUpdateState();
|
||||
OnStateUpdate?.Invoke(this);
|
||||
}
|
||||
|
||||
protected virtual void OnTransitionedToState(IState from) { }
|
||||
public void TransitionTo(IState from)
|
||||
{
|
||||
OnTransitionedToState(from);
|
||||
OnStateTransitionedTo?.Invoke(this, from);
|
||||
}
|
||||
|
||||
protected virtual void OnTransitionedFromState(IState to) { }
|
||||
public void TransitionFrom(IState to)
|
||||
{
|
||||
OnTransitionedFromState(to);
|
||||
OnStateTransitionedFrom?.Invoke(this, to);
|
||||
}
|
||||
|
||||
public abstract IState? GetNextState();
|
||||
}
|
Reference in New Issue
Block a user