-
Notifications
You must be signed in to change notification settings - Fork 3
/
FlipFsmBool.cs
81 lines (58 loc) · 2.01 KB
/
FlipFsmBool.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
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.StateMachine)]
[Tooltip("Flips the value of a Bool Variable in another FSM.")]
public class FlipFsmBool : FsmStateAction
{
[RequiredField]
[Tooltip("The GameObject that owns the FSM.")]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.FsmName)]
[Tooltip("Optional name of FSM on Game Object")]
public FsmString fsmName;
[RequiredField]
[UIHint(UIHint.FsmBool)]
[Tooltip("The name of the FSM variable.")]
public FsmString variableName;
GameObject goLastFrame;
string fsmNameLastFrame;
PlayMakerFSM fsm;
public override void Reset()
{
gameObject = null;
fsmName = "";
}
public override void OnEnter()
{
DoFlipFsmBool();
}
void DoFlipFsmBool()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}
// FIX: must check as well that the fsm name is different.
if (go != goLastFrame || fsmName.Value != fsmNameLastFrame)
{
goLastFrame = go;
fsmNameLastFrame = fsmName.Value;
// only get the fsm component if go or fsm name has changed
fsm = ActionHelpers.GetGameObjectFsm(go, fsmName.Value);
}
if (fsm == null)
{
LogWarning("Could not find FSM: " + fsmName.Value);
return;
}
var fsmBool = fsm.FsmVariables.FindFsmBool(variableName.Value);
{
fsmBool.Value = !fsmBool.Value;
Finish();
}
}
}
}