namespace Spine.Unity { public static class SkeletonAnimationExt { /// /// 当前动作的时间 /// /// /// 单位: 秒 public static float GetDuration(this SkeletonAnimation animation) { if (!animation.valid) { return 0; } else { TrackEntry entry = animation.state.GetCurrent(0); return entry?.Animation.Duration ?? 0; } } /// /// 当前动作的时间 /// /// /// 单位: 毫秒 public static int GetDurationMS(this SkeletonAnimation animation) { var duration = GetDuration(animation); return UnityEngine.Mathf.CeilToInt(duration * 1000); } /// /// 指定动作的持续时间 /// /// /// 动作名字 /// 单位: 秒 public static float GetDuration(this SkeletonAnimation animation, string aniName) { var animationObject = animation.skeletonDataAsset.GetSkeletonData(false).FindAnimation(aniName); return animationObject.Duration; } } }