diff options
author | chai <chaifix@163.com> | 2021-07-07 22:13:48 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-07-07 22:13:48 +0800 |
commit | 3db514468fac20693a257179d35592d0b78e2936 (patch) | |
tree | ef0f63324299a1121a76bbe470140b461666303e /Assets/Scripts/Unit/RootMotion/RootMotionData.cs | |
parent | a13f10139d33264fc9ebc5a15c75faf16fc7757e (diff) |
+RootMotion
Diffstat (limited to 'Assets/Scripts/Unit/RootMotion/RootMotionData.cs')
-rw-r--r-- | Assets/Scripts/Unit/RootMotion/RootMotionData.cs | 22 |
1 files changed, 21 insertions, 1 deletions
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<Vector3> 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);
+ }
}
|