Playmaker Forum

PlayMaker Feedback => Action Requests => Topic started by: jeanfabre on December 27, 2011, 06:08:57 AM

Title: Get Animation Speed
Post by: jeanfabre on December 27, 2011, 06:08:57 AM
Hi,

 Following Mark_T request, please find a getAnimationSpeed custom action

this action is now on the Ecosystem (http://j.mp/PlayMakerEcosystem)

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Animation)]
[Tooltip("Get the current Speed of an Animation, Normalize is generaly used during blending. Check Every Frame to update the time continuously.")]
public class GetAnimationSpeed : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(Animation))]
public FsmOwnerDefault gameObject;
[RequiredField]
[UIHint(UIHint.Animation)]
public FsmString animName;
[UIHint(UIHint.Variable)]
public FsmFloat speed;
public bool normalized;
public bool everyFrame;

public override void Reset()
{
gameObject = null;
animName = null;
speed = null;
normalized = false;
everyFrame = false;
}

public override void OnEnter()
{
DoGetAnimationSpeed(gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : gameObject.GameObject.Value);

if (!everyFrame)
Finish();
}

public override void OnUpdate()
{
DoGetAnimationSpeed(gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : gameObject.GameObject.Value);
}

void DoGetAnimationSpeed(GameObject go)
{
if (go == null) return;

if (go.animation == null)
{
LogWarning("Missing animation component: " + go.name);
return;
}


AnimationState anim = go.animation[animName.Value];

if (anim == null)
{
LogWarning("Missing animation: " + animName.Value);
return;
}

if (normalized)
{
speed.Value = anim.normalizedSpeed ;
}
else
{
speed.Value = anim.speed;
}

}

}
}

Bye,

 Jean
Title: Re: Get Animation Speed
Post by: Mark_T on December 27, 2011, 09:34:35 AM

Many thanks for your help.  :)