Created
April 13, 2017 20:37
-
-
Save mattluard/f602382b5744fb492c15e2aa0c68efbc to your computer and use it in GitHub Desktop.
Spine Cutscene Director Timeline Action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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