-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathStateMachineBuilder.cs
62 lines (57 loc) · 2.24 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
namespace RSG
{
/// <summary>
/// Entry point for fluent API for constructing states.
/// </summary>
public class StateMachineBuilder
{
/// <summary>
/// Root level state.
/// </summary>
private readonly State rootState;
/// <summary>
/// Entry point for constructing new state machines.
/// </summary>
public StateMachineBuilder()
{
rootState = new State();
}
/// <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()
{
return new StateBuilder<T, StateMachineBuilder>(this, rootState);
}
/// <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()
{
return new StateBuilder<T, StateMachineBuilder>(this, rootState, 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)
{
return new StateBuilder<State, StateMachineBuilder>(this, rootState, stateName);
}
/// <summary>
/// Return the root state once everything has been set up.
/// </summary>
public IState Build()
{
return rootState;
}
}
}