playMaker

Author Topic: Get Animation Time  (Read 5273 times)

Mark_T

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 72
Get Animation Time
« on: December 26, 2011, 01:03:31 PM »

I was looking for "Get Animation Time" but there is no such action.
I was able to stop an animation at a certain point with "Stop Animation", and my intention was to store the animation time in a variable and use it with "Set Animation Time", and continue the animation from that very moment it was stopped.
I also think a "Get Animation Speed" it might be useful.

Thanks in advance,

« Last Edit: December 26, 2011, 07:52:53 PM by Mark_T »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Animation Time
« Reply #1 on: December 27, 2011, 06:07:50 AM »
Hi Mark_T
 
Here we go.

 test it and tell me if that all works for you ( getAnimationSpeed on a new request thread for clarity)

Action is not available 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 Time of an Animation, Normalize time means 0 (start) to 1 (end); useful if you don't care about the exact time. Check Every Frame to update the time continuosly.")]
public class GetAnimationTime : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(Animation))]
public FsmOwnerDefault gameObject;
[RequiredField]
[UIHint(UIHint.Animation)]
public FsmString animName;
[UIHint(UIHint.Variable)]
public FsmFloat time;
public bool normalized;
public bool everyFrame;

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

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

if (!everyFrame)
Finish();
}

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

void DoGetAnimationTime(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)
{
time.Value = anim.normalizedTime ;
}
else
{
time.Value = anim.time;
}

}

}
}

Bye,

 Jean
« Last Edit: May 06, 2016, 02:58:10 AM by jeanfabre »

Mark_T

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 72
Re: Get Animation Time
« Reply #2 on: December 27, 2011, 09:32:38 AM »

Haha, a second visit from Santa this year.

It`s working perfectly. The setup was a bit different than I initially planned (still learning), but in the end, I managed to get it done with less states than expected.

Thank you so much. :)




jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Animation Time
« Reply #3 on: December 28, 2011, 03:37:41 AM »
Hi,

 Dont' fear the number of states, I do find that the more states, the better I can read and analyze it. So optimization is not (in my opinion of course...) in reducing the number of states, but actually in reducing the number of actions per state and really make most of the visualizations wonder of fsm and links between states. You won't loose any performances by linking more states together.

 
 Bye,

 Jean

Mark_T

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 72
Re: Get Animation Time
« Reply #4 on: December 28, 2011, 07:25:04 PM »

Thanks for the tips.
I didn`t thought about the amount of actions executed in each state.
Haha, maybe because I`m more a kind of a visual guy, the states are more "visible" to me. :)


mTruly

  • Junior Playmaker
  • **
  • Posts: 98
Re: Get Animation Time
« Reply #5 on: April 25, 2016, 12:27:10 PM »
Would be nice if this action was added to the Ecosystem.

Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Animation Time
« Reply #6 on: May 06, 2016, 02:58:38 AM »
Hi,

 Done, it's now available on the Ecosystem,

 Bye,

 Jean