playMaker

Author Topic: Rewind Animation  (Read 10631 times)

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4005
  • Official Playmaker Support
    • LinkedIn
Rewind Animation
« on: October 17, 2011, 11:14:33 AM »
Action to rewind a named animation.

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

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Animation)]
[Tooltip("Rewinds the named animation.")]
public class RewindAnimation : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(Animation))]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Animation)]
public FsmString animName;

public override void Reset()
{
gameObject = null;
animName = null;
}

public override void OnEnter()
{
DoRewindAnimation();

Finish();
}

void DoRewindAnimation()
{
if (string.IsNullOrEmpty(animName.Value))
{
return;
}

var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}

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

go.animation.Rewind(animName.Value);
}
}
}
« Last Edit: October 17, 2011, 11:16:42 AM by alexchouls »