-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExampleStateController.cs
103 lines (79 loc) · 2.49 KB
/
ExampleStateController.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections;
using UnityEngine.SceneManagement;
namespace SFI.GameStates
{
public class ExampleStateController : StateControllerBase
{
void Awake()
{
Init();
//create your states here.
var loadingState = new ExampleState();
var secondState = new SecondState(this); // pass a Monobehavior to a state's constructor to use a coroutine
var thirdState = new ThirdState();
//add transitions between states here
_stateMachine.AddTransition(loadingState, secondState,
()=> SceneManager.GetActiveScene().name == "IntroScene" );
//this second transition relies on the state change to occur from within the state
_stateMachine.AddTransition(secondState, thirdState,
()=> secondState.Finished);
//another example of a transition might be to test a Singleton
//_stateMachine.AddTransition(secondState, thirdState, ()=> MySingletonFromAnotherSystem.IsFinished);
//Set the first state. You can pass any state in as the starting state.
_stateMachine.SetState(_stateMachine.GetStartingTransition());
}
}
internal class ExampleState : IState
{
//called every Update(). You can add a FixedUpdateTick() if you need it
public void Tick()
{
}
//initialization code
public void OnEnter()
{
}
//clean up code
public void OnExit()
{
}
}
//Do more things here!
internal class SecondState : IState
{
public SecondState(StateControllerBase controllerBase)
{
controllerBase.StartCoroutine(YouCanAddCoroutines());
}
private IEnumerator YouCanAddCoroutines()
{
yield return null;
Finished = true;
}
public void Tick()
{
//is animation finished?
Finished = true;
}
public void OnEnter()
{
}
public void OnExit()
{
}
public bool Finished { get; set; }
}
internal class ThirdState : IState
{
public void Tick()
{
}
public void OnEnter()
{
}
public void OnExit()
{
}
}
}