Playmaker Forum

PlayMaker Updates & Downloads => Official Action Updates => Topic started by: Alex Chouls on October 17, 2011, 11:14:33 AM

Title: Rewind Animation
Post by: Alex Chouls 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);
}
}
}