Hello all.
I’m trying to reduce the manual labor involved in our art pipeline from Maya → Unity. Specifically, by using custom attributes to transfer and import alpha animation keys (these are not supported by default).
I’m stuck on generating curves for Mecanim in an AssetPostProcessor. You can see my script below, and you can see in the comments what the different debug logs are giving me. No animationcurves are being saved. The reason I’m doing this, is because we have a system in place to use these curves in Mecanim to drive all of our alpha and UV-scroll animation.
Just to be clear, this image shows which curves I’m trying to modify from script:
Any help here?
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
public class EffectsImporter : AssetPostprocessor {
void OnPostprocessGameObjectWithUserProperties(GameObject go, string[] propNames, System.Object[] values)
{
Debug.Log("OnPostprocessGameObjectWithUserProperties");
ModelImporter mi = assetImporter as ModelImporter;
for (int i = 0; i < propNames.Length; i++)
{
if (propNames[i].ToLower().Contains("alpha"))
{
ClipAnimationInfoCurve clipAnimInfoCurve = new ClipAnimationInfoCurve();
AnimationCurve alphaCurve = new AnimationCurve();
if (mi.clipAnimations[0].curves.Length < 1)
{
Debug.Log("0 existing curves");
}
List<ClipAnimationInfoCurve> allcurves = new List<ClipAnimationInfoCurve>(mi.clipAnimations[0].curves);
int keyFrame = alphaCurve.AddKey(0.2f, (float)values[i]);
int endFrame = alphaCurve.AddKey(1f, 1f);
clipAnimInfoCurve.curve = alphaCurve;
Debug.Log("keyframe result: "+clipAnimInfoCurve.curve.keys.Length);
allcurves.Add(clipAnimInfoCurve);
Debug.Log("trying to add "+allcurves.Count+ " curves"); // this prints 1 curve.
mi.clipAnimations[0].curves = allcurves.ToArray();
Debug.Log("mi clip length: "+mi.clipAnimations[0].curves.Length); // this prints 0
AssetDatabase.WriteImportSettingsIfDirty(mi.assetPath);
AssetDatabase.SaveAssets();
//This results in 0 curves saved
}
}
}
}