public RootMotionInfo GetAnimationRootMotionInfo(Animation animation, float currentTime) { RootMotionInfo rootMotion = new RootMotionInfo(); float duration = animation.Duration; float mid = duration * 0.5f; rootMotion.timeIsPastMid = currentTime > mid; TranslateTimeline timeline = animation.FindTranslateTimelineForBone(rootMotionBoneIndex); if (timeline != null) { rootMotion.start = timeline.Evaluate(0); rootMotion.current = timeline.Evaluate(currentTime); rootMotion.mid = timeline.Evaluate(mid); rootMotion.end = timeline.Evaluate(duration); return(rootMotion); } TranslateXTimeline xTimeline = animation.FindTimelineForBone <TranslateXTimeline>(rootMotionBoneIndex); TranslateYTimeline yTimeline = animation.FindTimelineForBone <TranslateYTimeline>(rootMotionBoneIndex); if (xTimeline != null || yTimeline != null) { rootMotion.start = TimelineExtensions.Evaluate(xTimeline, yTimeline, 0); rootMotion.current = TimelineExtensions.Evaluate(xTimeline, yTimeline, currentTime); rootMotion.mid = TimelineExtensions.Evaluate(xTimeline, yTimeline, mid); rootMotion.end = TimelineExtensions.Evaluate(xTimeline, yTimeline, duration); return(rootMotion); } return(rootMotion); }
Vector2 GetTimelineMovementDelta(float startTime, float endTime, TranslateXTimeline xTimeline, TranslateYTimeline yTimeline, Animation animation) { Vector2 currentDelta; if (startTime > endTime) // Looped { currentDelta = (TimelineExtensions.Evaluate(xTimeline, yTimeline, animation.Duration) - TimelineExtensions.Evaluate(xTimeline, yTimeline, startTime)) + (TimelineExtensions.Evaluate(xTimeline, yTimeline, endTime) - TimelineExtensions.Evaluate(xTimeline, yTimeline, 0)); } else if (startTime != endTime) // Non-looped { currentDelta = TimelineExtensions.Evaluate(xTimeline, yTimeline, endTime) - TimelineExtensions.Evaluate(xTimeline, yTimeline, startTime); } else { currentDelta = Vector2.zero; } return(currentDelta); }