playMaker

Author Topic: Get Animation Speed  (Read 3404 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Get Animation Speed
« 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

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
« Last Edit: May 06, 2016, 03:01:21 AM by jeanfabre »

Mark_T

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 72
Re: Get Animation Speed
« Reply #1 on: December 27, 2011, 09:34:35 AM »

Many thanks for your help.  :)