/
IntRangeSwitch.cs
90 lines (67 loc) · 1.7 KB
/
IntRangeSwitch.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
// Eric Vander Wal
// Dumb Game Dev
// www.dumbgamedev.com
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Sends an Event based on a Int variable range. The lowest value of the first range is automatically set to 0. Set your max value. The lowest number for each next range is set automatically.")]
public class IntRangeSwitch : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmInt intVariable;
[CompoundArray("Int Ranges", "Range Max", "Send Event")]
public FsmInt[] compareMax;
public FsmEvent[] sendEvent;
public bool everyFrame;
// Private Variables
private int smallestNumber;
private int largestNumber;
public override void Reset()
{
intVariable = null;
compareMax = new FsmInt[1];
sendEvent = new FsmEvent[1];
everyFrame = false;
}
public override void OnEnter()
{
DoIntRange();
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoIntRange();
}
void DoIntRange()
{
if (intVariable.IsNone) {
return;
}
// Setup Logic
for (int i = 0; i < compareMax.Length; i++)
{
if(compareMax[i].Value == compareMax[0].Value)
{
smallestNumber = 0;
}
else
{
smallestNumber = compareMax[i-1].Value + 1;
}
largestNumber = compareMax[i].Value;
// Switch Logic
if (intVariable.Value>=smallestNumber&intVariable.Value<=largestNumber)
{
{
Fsm.Event(sendEvent[i]);
return;
}
/// End switch Logic
}
}
}
}
}