playMaker

Author Topic: Is Animation Playing  (Read 3383 times)

pedroathumanspot

  • Playmaker Newbie
  • *
  • Posts: 11
Is Animation Playing
« on: January 23, 2013, 06:57:04 PM »
On the follow up of this topic, here's a custom action to know if a particular Animation is playing or not, storing the value on a variable:

Code: [Select]
/ * Is Animation Playing - Playmaker Custom Action
  * https://github.com/pedrosanta/PlaymakerActions */

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);

Finish();
}
}
}

Additionally I will be maintaining a custom actions repository on https://github.com/pedrosanta/PlaymakerActions. Feel free to fork it away and collaborate. :)

Cheers.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Is Animation Playing
« Reply #1 on: September 24, 2013, 06:22:58 AM »
Hi,

 Your link to github is broken. Do you still maintain a rep somewhere?

 someone just asked for your action :)

bye,

 Jean