Aloento / SuperSpineViewer

A tool to load and export Spine skel & 一个拿来加载与导出Spine骨骼的工具
Apache License 2.0
217 stars 25 forks source link

暂停后重新播放不从原来停下的地方恢复 #13

Closed Aloento closed 3 years ago

Aloento commented 3 years ago

可能的解决方案

using System.Collections;
using UnityEngine;
using Spine.Unity;

public class AnimationStateTesting : MonoBehaviour
{
   IEnumerator Start() {
      SkeletonAnimation skeletonAnimation = this.GetComponent<SkeletonAnimation>();
      yield return new WaitForSeconds(1);

      // Pauses playback
      skeletonAnimation.AnimationState.TimeScale = 0;
      float savedTrackTime01 = skeletonAnimation.AnimationState.Tracks.Items[0].TrackTime;
      yield return new WaitForSeconds(1);

      // Resumes playback
      skeletonAnimation.AnimationState.TimeScale = 1;
      yield return new WaitForSeconds(1);

      // Sets playback position of first track to saved pause position.
      // Note that this is a simple version for only a single track, which also does not
      // respect if a different animation is already playing.
      skeletonAnimation.AnimationState.Tracks.Items[0].TrackTime = savedTrackTime01;
   }
}
Aloento commented 3 years ago

c67e03365e7c5d67a4f7d3c906c96bfd67f068e9