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