Playmaker Forum

PlayMaker Feedback => Action Requests => Topic started by: ermak on February 01, 2013, 10:40:26 AM

Title: 2D Toolkit 1.90 - "IsPlaying(clip)" Action
Post by: ermak on February 01, 2013, 10:40:26 AM
Hello,

Last version of 2D Toolkit 1.90 (http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,1091.0.html?PHPSESSID=l7bd3fqm341h9i30p4cb8kcip0) 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!
Title: Re: 2D Toolkit 1.90 - "IsPlaying(clip)" Action
Post by: jeanfabre on February 02, 2013, 03: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
Title: Re: 2D Toolkit 1.90 - "IsPlaying(clip)" Action
Post by: jeanfabre on March 15, 2013, 09:56:16 AM
Hi,

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

bye,

 Jean