playMaker

Author Topic: 2D Toolkit Custom Play Animation Action  (Read 1479 times)

fimmfingur

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
2D Toolkit Custom Play Animation Action
« on: October 26, 2012, 03:16:03 AM »
I made a small change to the Action that comes with the 2DTK download from here
https://hutonggames.fogbugz.com/default.asp?W717

All i did was change the PlayAnimation action so that I didn't to add a StopAnimation action before every play animation action.

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

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("2D ToolKit/Sprite")]
    [Tooltip("Plays a sprite animation. \nNOTE: The Game Object must have a tk2dAnimatedSprite attached.")]
    public class Tk2dPlayNewAnimation : FsmStateAction
    {
        [RequiredField]
        [Tooltip("The Game Object to work with. NOTE: The Game Object must have a tk2dAnimatedSprite component attached.")]
        [CheckForComponent(typeof(tk2dAnimatedSprite))]
        public FsmOwnerDefault gameObject;

        [RequiredField]
        [Tooltip("The clip name to play")]
        public FsmString clipName;


        private tk2dAnimatedSprite _sprite;

        private void _getSprite()
        {
            GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
            if (go == null)
            {
                return;
            }

            _sprite = go.GetComponent<tk2dAnimatedSprite>();
        }


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

        public override void OnEnter()
        {
            _getSprite();

            DoPlayAnimation();
        }

        void DoPlayAnimation()
        {
            if (_sprite == null)
            {
                LogWarning("Missing tk2dAnimatedSprite component");
                return;
            }

                _sprite.Play(clipName.Value);
           
        }
    }

}