-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlayMakerExtensions.cs
95 lines (83 loc) · 3.13 KB
/
PlayMakerExtensions.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
using HutongGames.PlayMaker;
namespace Fyrenest
{
internal static class PlayMakerExtensions
{
internal static FsmState AddState(this PlayMakerFSM fsm, string name)
{
var dest = new FsmState[fsm.FsmStates.Length + 1];
Array.Copy(fsm.FsmStates, dest, fsm.FsmStates.Length);
var newState = new FsmState(fsm.Fsm)
{
Name = name,
Transitions = Array.Empty<FsmTransition>(),
Actions = Array.Empty<FsmStateAction>()
};
dest[fsm.FsmStates.Length] = newState;
fsm.Fsm.States = dest;
return newState;
}
internal static FsmState GetState(this PlayMakerFSM fsm, string name)
{
return fsm.FsmStates.FirstOrDefault(s => s.Name == name);
}
internal static void RemoveAction(this FsmState s, int i)
{
var actions = new FsmStateAction[s.Actions.Length - 1];
Array.Copy(s.Actions, actions, i);
Array.Copy(s.Actions, i + 1, actions, i, s.Actions.Length - i - 1);
s.Actions = actions;
}
internal static void AddAction(this FsmState s, Action a)
{
SpliceAction(s, s.Actions.Length, a);
}
internal static void AppendAction(this FsmState s, Action a)
{
AddAction(s, a);
}
internal static void SpliceAction(this FsmState s, int pos, Action a)
{
var actions = new FsmStateAction[s.Actions.Length + 1];
Array.Copy(s.Actions, actions, pos);
actions[pos] = new FuncAction(a);
Array.Copy(s.Actions, pos, actions, pos + 1, s.Actions.Length - pos);
s.Actions = actions;
//a.Init(s);
}
internal static void PrependAction(this FsmState s, Action a)
{
SpliceAction(s, 0, a);
}
internal static void ReplaceAction(this FsmState s, int i, Action a)
{
FuncAction action = new(a);
action.Init(s);
s.Actions[i] = action;
}
internal static void AddTransition(this FsmState s, string eventName, string toState)
{
var transitions = new FsmTransition[s.Transitions.Length + 1];
Array.Copy(s.Transitions, transitions, s.Transitions.Length);
transitions[s.Transitions.Length] = new FsmTransition
{
FsmEvent = FsmEvent.GetFsmEvent(eventName),
ToFsmState = s.Fsm.GetState(toState),
ToState = toState,
};
s.Transitions = transitions;
}
internal static void RemoveAllTransitions(this FsmState s)
{
s.Transitions = new FsmTransition[0];
}
internal static FsmInt GetFsmInt(this PlayMakerFSM fsm, string name)
{
return fsm.FsmVariables.IntVariables.FirstOrDefault(v => v.Name == name);
}
internal static FsmBool GetFsmBool(this PlayMakerFSM fsm, string name)
{
return fsm.FsmVariables.BoolVariables.FirstOrDefault(v => v.Name == name);
}
}
}