-
Notifications
You must be signed in to change notification settings - Fork 0
/
StateMachine.cs
70 lines (59 loc) · 1.32 KB
/
StateMachine.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
using Godot;
using System.Collections.Generic;
public partial class StateMachine : Node
{
public string state = null;
public string previousState = null;
public Dictionary<string, string> states = new Dictionary<string, string>();
public Node parent;
public override void _Ready()
{
parent = GetParent<Node>();
}
public override void _PhysicsProcess(double delta)
{
if (state != null)
{
StateLogic(delta);
var transition = GetTransition(delta);
if (transition != null)
{
SetState(transition);
}
}
}
public void StateLogic(double delta)
{
// Implement logic for the current state here
}
public string GetTransition(double delta)
{
// Implement logic for determining state transitions here
return null;
}
public void EnterState(string newState, string oldState)
{
// Implement behavior to execute when entering a new state
}
public void ExitState(string oldState, string newState)
{
// Implement behavior to execute when exiting the current state
}
public void SetState(string newState)
{
previousState = state;
state = newState;
if (previousState != null)
{
ExitState(previousState, newState);
}
if (newState != null)
{
EnterState(newState, previousState);
}
}
public void AddState(string stateName)
{
states[stateName] = states.Count.ToString();
}
}