示例#1
0
        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);
        }
示例#2
0
        Vector2 GetTimelineMovementDelta(float startTime, float endTime,
                                         TranslateTimeline timeline, Animation animation)
        {
            Vector2 currentDelta;

            if (startTime > endTime)             // Looped
            {
                currentDelta = (timeline.Evaluate(animation.Duration) - timeline.Evaluate(startTime))
                               + (timeline.Evaluate(endTime) - timeline.Evaluate(0));
            }
            else if (startTime != endTime)             // Non-looped
            {
                currentDelta = timeline.Evaluate(endTime) - timeline.Evaluate(startTime);
            }
            else
            {
                currentDelta = Vector2.zero;
            }
            return(currentDelta);
        }