forked from Real-Serious-Games/Fluent-State-Machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStateMachineBuilder.cs
46 lines (42 loc) · 1.97 KB
/
StateMachineBuilder.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
namespace Azur.StateMachine
{
/// <summary>
/// Entry point for fluent API for constructing states.
/// </summary>
public sealed class StateMachineBuilder
{
/// <summary>
/// Root level state.
/// </summary>
private readonly State _root = new();
/// <summary>
/// Create a new state of a specified type and add it as a child of the root state.
/// </summary>
/// <typeparam name="T">Type of the state to add</typeparam>
/// <returns>Builder used to configure the new state</returns>
public IStateBuilder<T, StateMachineBuilder> State<T>() where T : AbstractState, new() =>
new StateBuilder<T, StateMachineBuilder>(this, _root);
/// <summary>
/// Create a new state of a specified type with a specified name and add it as a
/// child of the root state.
/// </summary>
/// <typeparam name="T">Type of the state to add</typeparam>
/// <param name="stateName">Name for the new state</param>
/// <returns>Builder used to configure the new state</returns>
public IStateBuilder<T, StateMachineBuilder> State<T>(string stateName) where T : AbstractState, new() =>
new StateBuilder<T, StateMachineBuilder>(this, _root, stateName);
/// <summary>
/// Create a new state with a specified name and add it as a
/// child of the root state.
/// </summary>
/// <param name="stateName">Name for the new state</param>
/// <returns>Builder used to configure the new state</returns>
public IStateBuilder<State, StateMachineBuilder> State(string stateName) =>
new StateBuilder<State, StateMachineBuilder>(this, _root, stateName);
/// <summary>
/// Return the root state once everything has been set up.
/// </summary>
public IState Build() =>
_root;
}
}