|
@@ -196,24 +196,39 @@ namespace Spine.Unity {
|
|
|
public Vector2 GetAnimationRootMotion (float startTime, float endTime,
|
|
|
Animation animation) {
|
|
|
|
|
|
- var timeline = animation.FindTranslateTimelineForBone(rootMotionBoneIndex);
|
|
|
+ TranslateTimeline timeline = animation.FindTranslateTimelineForBone(rootMotionBoneIndex);
|
|
|
if (timeline != null) {
|
|
|
return GetTimelineMovementDelta(startTime, endTime, timeline, animation);
|
|
|
}
|
|
|
+ TranslateXTimeline xTimeline = animation.FindTimelineForBone<TranslateXTimeline>(rootMotionBoneIndex);
|
|
|
+ TranslateYTimeline yTimeline = animation.FindTimelineForBone<TranslateYTimeline>(rootMotionBoneIndex);
|
|
|
+ if (xTimeline != null || yTimeline != null) {
|
|
|
+ return GetTimelineMovementDelta(startTime, endTime, xTimeline, yTimeline, animation);
|
|
|
+ }
|
|
|
return Vector2.zero;
|
|
|
}
|
|
|
|
|
|
public RootMotionInfo GetAnimationRootMotionInfo (Animation animation, float currentTime) {
|
|
|
RootMotionInfo rootMotion = new RootMotionInfo();
|
|
|
- var timeline = animation.FindTranslateTimelineForBone(rootMotionBoneIndex);
|
|
|
+ float duration = animation.Duration;
|
|
|
+ float mid = duration * 0.5f;
|
|
|
+ rootMotion.timeIsPastMid = currentTime > mid;
|
|
|
+ TranslateTimeline timeline = animation.FindTranslateTimelineForBone(rootMotionBoneIndex);
|
|
|
if (timeline != null) {
|
|
|
- float duration = animation.Duration;
|
|
|
- float mid = duration * 0.5f;
|
|
|
rootMotion.start = timeline.Evaluate(0);
|
|
|
rootMotion.current = timeline.Evaluate(currentTime);
|
|
|
rootMotion.mid = timeline.Evaluate(mid);
|
|
|
rootMotion.end = timeline.Evaluate(duration);
|
|
|
- rootMotion.timeIsPastMid = currentTime > mid;
|
|
|
+ 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;
|
|
|
}
|
|
@@ -232,6 +247,24 @@ namespace Spine.Unity {
|
|
|
return currentDelta;
|
|
|
}
|
|
|
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
void GatherTopLevelBones () {
|
|
|
topLevelBones.Clear();
|
|
|
var skeleton = skeletonComponent.Skeleton;
|