-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIStateMachine.cs
More file actions
42 lines (35 loc) · 1.48 KB
/
IStateMachine.cs
File metadata and controls
42 lines (35 loc) · 1.48 KB
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
using Exanite.Core.Collections;
namespace CodeName.StateMachines
{
public interface IStateMachine<TState> where TState : IState
{
public TState DefaultState { get; set; }
public TState CurrentState { get; }
/// <summary>
/// Attempts to transition to the new <see cref="state"/>.
/// Returns true if the <see cref="CurrentState"/> was already set to <see cref="state"/>
/// or it was changed to <see cref="state"/>.
/// </summary>
public bool TrySetState(TState state);
/// <summary>
/// Transitions to the new <see cref="state"/> without checking for <see cref="IState.CanEnterState"/> and <see cref="IState.CanExitState"/>.
/// </summary>
public void ForceSetState(TState state);
/// <summary>
/// Called before the previous state is exited.
/// </summary>
public event StateChangedEvent<TState> StateChanging;
/// <summary>
/// Called after the previous state is exited AND before the new state is entered.
/// </summary>
public event StateChangedEvent<TState> StateChangeInProgress;
/// <summary>
/// Called after the new state is entered.
/// </summary>
public event StateChangedEvent<TState> StateChanged;
}
public interface IStateMachine<TKey, TState> : IStateMachine<TState> where TState : IState
{
public IReadOnlyTwoWayDictionary<TKey, TState> RegisteredStates { get; }
}
}