-
Notifications
You must be signed in to change notification settings - Fork 2
/
IStateContext.cs
51 lines (44 loc) · 1.66 KB
/
IStateContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
namespace Game.FSM
{
/// <summary>
/// State context. Acts as a parent node in a state hierarchy graph.
/// </summary>
public interface IStateContext
{
/// <summary>
/// Invoked when the innermost active child state is changed.
/// </summary>
event Action<IState> OnLeafStateChanged;
/// <summary>
/// Current innermost active child state.
/// </summary>
IState ActiveLeafState { get; }
/// <summary>
/// Current immediate child state in this context.
/// </summary>
IState ActiveState { get; }
/// <summary>
/// Next transition to execute.
/// </summary>
TransitionBase NextTransition { set; }
/// <summary>
/// Executes the next transition in this context or any of it's children in the active branch.
/// </summary>
/// <returns>True if transition was executed.</returns>
bool ExecuteNextTransition();
/// <summary>
/// Immediately switch to a new state.
/// </summary>
/// <param name="newState"></param>
void SwitchState(IState newState);
/// <summary>
/// Triggers the event for the active states to handle.
/// </summary>
/// <param name="stateEvent">Event data.</param>
/// <param name="allowTransition">Allow transitions to be executed automatically after event is handled.</param>
/// <typeparam name="T">Type of event.</typeparam>
/// <returns>True if event was handled by any active state.</returns>
bool TriggerEvent<T>(T stateEvent, bool allowTransition = true);
}
}