From 3db514468fac20693a257179d35592d0b78e2936 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 7 Jul 2021 22:13:48 +0800 Subject: +RootMotion --- Assets/Scripts/Unit/RootMotion/RootMotionData.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'Assets/Scripts/Unit/RootMotion/RootMotionData.cs') diff --git a/Assets/Scripts/Unit/RootMotion/RootMotionData.cs b/Assets/Scripts/Unit/RootMotion/RootMotionData.cs index 44f3d294..4fe2db97 100644 --- a/Assets/Scripts/Unit/RootMotion/RootMotionData.cs +++ b/Assets/Scripts/Unit/RootMotion/RootMotionData.cs @@ -2,8 +2,28 @@ using System.Collections.Generic; using UnityEngine; +[CreateAssetMenu(fileName = "RootMotion Data")] +// 单个动画的root motion public class RootMotionData : ScriptableObject { - + public string animationName; + + public int frameCount; + + public List positionList; + + public float animationLength; + + public float fps; + + public Vector3 GetRootMotion(float normalTime) + { + normalTime = Mathf.Clamp(normalTime, 0, 1); + int prevFrame = (int)Mathf.Floor((frameCount - 1) * normalTime) % frameCount; + int nextFrame = (int)Mathf.Ceil((frameCount - 1) * normalTime) % frameCount; + float frameRate = 1 / fps; + float t = (normalTime * animationLength - prevFrame * frameRate) / frameRate; + return Vector3.Lerp(positionList[prevFrame], positionList[nextFrame], t); + } } -- cgit v1.1-26-g67d0