-
Notifications
You must be signed in to change notification settings - Fork 3
/
IsAnimationPlaying.cs
72 lines (55 loc) · 1.75 KB
/
IsAnimationPlaying.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
/ * Is Animation Playing - Playmaker Custom Action
* https://github.com/pedrosanta/PlaymakerActionsPack * /
using UnityEngine;
namespace HutongGames.PlayMaker.Actions{
[ActionCategory(ActionCategory.Animation)]
[Tooltip("Checks if the specified animation is playing and stores the result in a variable.\nCheckout the Animation.IsPlaying on the Unity Documentation for further details.")]
public class IsAnimationPlaying : FsmStateAction{
[RequiredField]
[CheckForComponent(typeof(Animation))]
[Tooltip("The game object with the animation.")]
public FsmOwnerDefault gameObject;
[RequiredField]
[UIHint(UIHint.Animation)]
[Tooltip("The name of the animation to check.")]
public FsmString animName;
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmBool storeValue;
public bool everyFrame;
public override void Reset(){
gameObject = null;
animName = "";
storeValue = null;
}
public override void OnEnter(){
DoIsAnimationPlaying(gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : gameObject.GameObject.Value);
if (!everyFrame)
Finish();
}
public override void OnUpdate(){
DoIsAnimationPlaying(gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : gameObject.GameObject.Value);
}
void DoIsAnimationPlaying(GameObject go){
if (storeValue == null) return;
if (go == null)
{
return;
}
if (go.animation == null)
{
LogWarning("Missing Animation component on GameObject: " + go.name);
Finish();
return;
}
var anim = go.animation[animName.Value];
if (anim == null)
{
LogWarning("Missing animation: " + animName.Value);
Finish();
return;
}
storeValue.Value = go.animation.IsPlaying(animName.Value);
}
}
}