Skip to content

Instantly share code, notes, and snippets.

@mattluard
Created April 13, 2017 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattluard/f602382b5744fb492c15e2aa0c68efbc to your computer and use it in GitHub Desktop.
Save mattluard/f602382b5744fb492c15e2aa0c68efbc to your computer and use it in GitHub Desktop.
Spine Cutscene Director Timeline Action
using UnityEngine;
using Spine.Unity;
namespace CinemaDirector {
[CutsceneItemAttribute("SkeletonAnimation", "Play Skeleton Animation", CutsceneItemGenre.ActorItem)]
public class PlaySkeletonAnimationEvent : CinemaActorAction {
public AnimationClip AnimationToPlay = null;
public int AnimationTrack = 0;
public void Update() {
}
public override void UpdateTime(GameObject Actor, float runningTime, float deltaTime) {
SkeletonAnimation animation = Actor.GetComponent<SkeletonAnimation>();
if (!animation || AnimationToPlay == null) {
return;
}
if (!animation.Initialized) {
animation.Initialize(false);
}
if (
animation.state.GetCurrent(AnimationTrack) == null ||
animation.state.GetCurrent(AnimationTrack).animation.name != AnimationToPlay.name
) {
animation.AnimationName = AnimationToPlay.name;
animation.state.SetAnimation(AnimationTrack, AnimationToPlay.name, false);
#if UNITY_EDITOR
if (UnityEditor.EditorApplication.isPlaying)
#endif
animation.Initialize(true);
}
float timeScale = AnimationToPlay.length / duration;
animation.state.GetCurrent(AnimationTrack).time = runningTime * timeScale;
animation.state.Apply(animation.skeleton);
}
public override void End(GameObject Actor) {
}
public override void Trigger(GameObject Actor) {
SkeletonAnimation animation = Actor.GetComponent<SkeletonAnimation>();
if (!animation || AnimationToPlay == null) {
return;
}
animation.Initialize(true);
UpdateTime(Actor, 0, 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment