Skip to content

Commit 7c7e0a9

Browse files
committed
Found a reasonably sensible way to implement the state pattern with the StateMachine
1 parent 9f06f2a commit 7c7e0a9

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

Runtime/StateGraph/StateMachine.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class StateMachine
1515
{
1616
public event Action<State, StateMachineModel> OnComplete;
1717

18+
public State State => _currentNode?.State;
1819
public StateMachineModel Model { get; private set; }
1920
public bool IsComplete { get; private set; }
2021

Runtime/StateGraph/StateMachineController.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using Nonatomic.VSM2.StateGraph.States;
23
using UnityEngine;
34

45
namespace Nonatomic.VSM2.StateGraph
@@ -12,6 +13,8 @@ public class StateMachineController : MonoBehaviour
1213
/// Gets the unique identifier for this controller.
1314
/// </summary>
1415
public string Id => _id;
16+
17+
public State State => _stateMachine?.State;
1518

1619
/// <summary>
1720
/// Gets the current StateMachineModel, either from the active state machine or the serialized field.
@@ -27,6 +30,15 @@ public class StateMachineController : MonoBehaviour
2730
private bool _activated;
2831
private bool _started;
2932

33+
/// <summary>
34+
/// Jumps to a state via a JumpIn state using the JumpId to identify the JumpIn node.
35+
/// </summary>
36+
/// <param name="id">The JumpIn id of the destination JumpIn node</param>
37+
public void JumpTo(JumpId id)
38+
{
39+
_stateMachine?.JumpTo(id);
40+
}
41+
3042
/// <summary>
3143
/// Changes the StateMachineModel and reinitializes the state machine.
3244
/// If the GameObject is active and has already started, it will also call Start and Enter on the new state machine.

0 commit comments

Comments
 (0)