PlayMaker Feedback > Action Requests
Get Animation Speed
(1/1)
jeanfabre:
Hi,
Following Mark_T request, please find a getAnimationSpeed custom action
this action is now on the Ecosystem
--- Code: ---// (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;
}
}
}
}
--- End code ---
Bye,
Jean
Mark_T:
Many thanks for your help. :)
Navigation
[0] Message Index
Go to full version