- Home /
Question by
Smileywolfe · May 16, 2019 at 12:22 AM ·
editorassetpostprocessorkeyframes
Help with AssetPostProcessor and keyframes?
Hi there,
I'm trying to use the AssetPostProcessor class to change all of my keyframe tangents to constant. This way I don't have to duplicate every animation clip and set all the keys manually.
Unfortunately, I don't really know what I'm doing and I'm not having a lot of luck getting my script to work. I have two variations of the same code block in OnPreprocessAnimation and OnPostProcessAnimation but I'm not having any luck with either. Can anyone help me?
void OnPreprocessAnimation () {
ModelImporter modelImporter = assetImporter as ModelImporter;
modelImporter.clipAnimations = modelImporter.defaultClipAnimations;
ModelImporterClipAnimation[] clips = modelImporter.clipAnimations;
foreach (ModelImporterClipAnimation clip in clips) {
ClipAnimationInfoCurve[] curves = clip.curves;
for (int i = 0; i < curves.Length; i++) {
AnimationCurve newCurve = curves[i].curve;
for (int j = 0; j < newCurve.keys.Length; j++) {
AnimationUtility.SetKeyLeftTangentMode(newCurve, j, AnimationUtility.TangentMode.Constant);
AnimationUtility.SetKeyRightTangentMode(newCurve, j, AnimationUtility.TangentMode.Constant);
}
}
clip.curves = curves;
}
modelImporter.clipAnimations = clips;
}
void OnPostprocessAnimation (GameObject import, AnimationClip clip) {
EditorCurveBinding[] bindings = AnimationUtility.GetObjectReferenceCurveBindings(clip);
for (int i = 0; i < bindings.Length; i++) {
AnimationCurve newCurve = AnimationUtility.GetEditorCurve(clip, bindings[i]);
for (int j = 0; j < newCurve.keys.Length; j++) {
AnimationUtility.SetKeyLeftTangentMode(newCurve, j, AnimationUtility.TangentMode.Constant);
AnimationUtility.SetKeyRightTangentMode(newCurve, j, AnimationUtility.TangentMode.Constant);
}
AnimationUtility.SetEditorCurve(clip, bindings[i], newCurve);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Importing lpc assets 0 Answers
2D Cut-Scene Animation: Is there any way to structure them? 0 Answers
Metadata not being saved on custom file types 0 Answers
adapting replace prefab example 1 Answer