• Unity
  • How does Spine implement sort playback in UnityEngine?

  • تم التحرير
Related Discussions
...

I made the animation using Spine software, which contains thousands of actions. I want to implement scripts in Unity Engine. When I import .atlas, .png, .json into Unity, Spine will automatically sort each of my animations in the background. The sorting is based on the imported chronological order, for example, from 01 to 10000. Then in the Inspector, there will be two text boxes. I can specify the serial number to play the animation segment between the two animations. It can automatically play the animations. . Because I can only animate one by one now, it is very complicated. I mean, the whole process realizes the process of automatically specifying the playback. Or other achievable methods. How do I implement this process? I can't find any information on the internet. If possible, leave examples. Thank you! 😃 😃


Because I made 10,000 animations in Spine, I need to do something like "animation check exhibition". Now I use these three pieces of code:
skeletonAnimation.timeScale = 1.5f;
skeletonAnimation.loop = true;
skeletonAnimation.AnimationName = "run";

To play the animation, but I have 10,000 actions and AnimationName has 10000, which means that I need to set 10,000 actions in skeletonAnimation, which is obviously impossible.

What I need is that I can sort the 10,000 animations internally, all the actions become a timeline, and then I can enter the serial number to play between certain clips. This effect is similar to Adobe Flash or video editing software. 😃 😃

You can play back all animations of a Skeleton with code like the following component:

using System.Collections.Generic;
using UnityEngine;

using Spine.Unity;
using Spine;

public class PlayAllAnimations : MonoBehaviour {

   IEnumerator<Spine.Animation> animationEnumerator;
   SkeletonAnimation skeletonAnimation;

   void Start () {
      skeletonAnimation = this.GetComponent<SkeletonAnimation>();
      var animationState = skeletonAnimation.AnimationState;
      var animations = skeletonAnimation.Skeleton.Data.Animations;
      animationEnumerator = animations.GetEnumerator();

  PlayNextAnimation(null);
   }

   private void PlayNextAnimation (TrackEntry unusedArgument) {
      if (!animationEnumerator.MoveNext())
         return;

  Spine.Animation animation = animationEnumerator.Current;
  Debug.Log("Playing " + animation.name);
  var trackEntry = skeletonAnimation.AnimationState.AddAnimation(0, animation, false, 0);
  trackEntry.Complete += PlayNextAnimation;
   }
}

In case you need to do something else with animations than playing them back (e.g. perform some editor scripting with every animation), then you can also iterate over skeletonAnimation.Skeleton.Data.Animations with a foreach() statement as usual.