playMaker

Author Topic: 2D Toolkit 1.90 - "IsPlaying(clip)" Action  (Read 2295 times)

ermak

  • Junior Playmaker
  • **
  • Posts: 60
    • View Profile
    • AL Games
2D Toolkit 1.90 - "IsPlaying(clip)" Action
« on: February 01, 2013, 08:40:26 AM »
Hello,

Last version of 2D Toolkit 1.90 have this:

- tk2dAnimatedSprite.IsPlaying(clip) will tell you if that clip is currently playing

Can we have this update here?
https://hutonggames.fogbugz.com/default.asp?W717

Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15318
  • Official Playmaker Support
    • View Profile
Re: 2D Toolkit 1.90 - "IsPlaying(clip)" Action
« Reply #1 on: February 02, 2013, 01:33:12 PM »
Hi,

 I'll put it here for now. It will be in the nest drop, when I will update the whole package.


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

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("2D ToolKit/Sprite")]
[Tooltip("Check if a sprite animation is playing. \nNOTE: The Game Object must have a tk2dAnimatedSprite attached.")]
public class Tk2dIsPlaying : 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;

[Tooltip("is the clip playing?")]
[UIHint(UIHint.Variable)]
public FsmBool isPlaying;

[Tooltip("EVvnt sent if clip is playing")]
public FsmEvent isPlayingEvent;

[Tooltip("Event sent if clip is not playing")]
public FsmEvent isNotPlayingEvent;

[Tooltip("Repeat every frame.")]
public bool everyframe;

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;
everyframe = false;

isPlayingEvent = null;
isNotPlayingEvent = null;

}

public override void OnEnter()
{
_getSprite();

DoIsPlaying();

if (!everyframe)
{
Finish();
}

}
public override void OnUpdate()
{
DoIsPlaying();
}


void DoIsPlaying()
{

if (_sprite == null)
{
LogWarning("Missing tk2dAnimatedSprite component: " + _sprite.gameObject.name);
return;
}

bool _isPlaying =_sprite.IsPlaying(clipName.Value);
isPlaying.Value = _isPlaying;

if (_isPlaying)
{
Fsm.Event(isPlayingEvent);
}else{
Fsm.Event(isNotPlayingEvent);
}


}

}
}


 bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15318
  • Official Playmaker Support
    • View Profile
Re: 2D Toolkit 1.90 - "IsPlaying(clip)" Action
« Reply #2 on: March 15, 2013, 06:56:16 AM »
Hi,

 Ok, the wiki page is now updated with the latest.

bye,

 Jean