Extending VSM
Previous State Cache Example
using Ilumisoft.VisualStateMachine;
using UnityEngine;
/// <summary>
/// Caches the id of the previous state, when the state machine switches states and provides a method to
/// enter it.
/// </summary>
public class PreviousStateCacheExample : MonoBehaviour
{
[SerializeField]
StateMachine stateMachine;
string previousStateID = string.Empty;
private void Awake()
{
if(stateMachine != null)
{
stateMachine.OnExitState += OnExitState;
}
else
{
Debug.LogWarning("No state machine assigned.", this);
}
}
private void OnExitState(State state)
{
previousStateID = state.ID;
}
public void EnterPreviousState()
{
if (stateMachine != null)
{
stateMachine.TriggerByState(previousStateID);
}
}
}State Machine Logger
Last updated