AnimationClip获取关键帧信息
1,关键帧数据都保存在AnimationCurve上,所以首先要获取到这个
public static AnimationCurve GetAnimCurve(AnimationClip clip, string path, string propName) { EditorCurveBinding[] bindings = AnimationUtility.GetCurveBindings(clip); foreach (var b in bindings) { if (b.path == path) { //Debug.Log($"path:{b.path}, propName:{b.propertyName}, discrete:{b.isDiscreteCurve}, pptr:{b.isPPtrCurve}"); if (b.propertyName == propName) { var result = AnimationUtility.GetEditorCurve(clip, b); return result; } } } return null; }
path和propName
2, 关键帧数据
public static void PrintCurve(AnimationCurve curve) { Debug.Log($"preWrap:{curve.preWrapMode}, postWrap:{curve.postWrapMode}, kfCnt:{curve.length}"); for (var i = 0; i < curve.keys.Length; ++i) { var kf = curve.keys[i]; Debug.Log($"keyFrame:{i}, t:{kf.time}, v:{kf.value}, mode:{kf.weightedMode}, in:{kf.inTangent}, inW:{kf.inWeight}, out:{kf.outTangent}, outW:{kf.outWeight}"); } }