- Home /
Modify a maya.mb in OnPostProcessAllAssets?
Is it possible to do the same operations that can be performed in OnPostProcessModel inside OnPostProcessAllAssets instead? Im unsure of the correct way of opening an mb asset, modifying and resaving it if that is possible. All the examples I have found for OnPostProcessModel seem to concentrate on updating some other prefab based on a changed model.
Im trying to work around a maya loading bug by reapplying animations from another directory using an an AssetPostprocessor. (the problem is that certain animations become corrupt after reloading the maya file in unity 4, so I have copied animations from unity 3.5 where they are working)
This code below works when reloading just the individual maya file, but stops working after a reload-all. Im thinking that perhaps OnPostProcessModel should not open other assets that themselves may not have been processed yet, so I wanted to try doing the same work in OnPostProcessAllAssets
using System.IO;
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
public class MayaModelFixer : AssetPostprocessor
{
void OnPostprocessModel(GameObject gameObjectRoot)
{
FixIfMayaModel(gameObjectRoot, "MyDirectory","MyMayaFileWithProblem");
}
void FixIfMayaModel(GameObject gameObjectRoot, string parentDir, string filename)
{
if(assetPath.EndsWith(parentDir+"/"+filename+".mb"))
{
LogWarning ("FixIfMayaModel FOUND:"+assetPath);
var clips = AnimationUtility.GetAnimationClips(gameObjectRoot.animation);
foreach(AnimationClip c in clips)
{
LogWarning ("CLIP:"+c.name);
string copyPath = "Assets/AnimationClipsFix/"+filename+"/"+c.name+".anim";
AnimationClip copySource = AssetDatabase.LoadAssetAtPath(copyPath, typeof(AnimationClip)) as AnimationClip;
if(null==copySource)
LogError ("Missing copy:"+c.name);
else
{
AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(copySource, true);
for (int i=0; i<curveDatas.Length; i++)
{
AnimationUtility.SetEditorCurve(
c,
curveDatas[i].path,
curveDatas[i].type,
curveDatas[i].propertyName,
curveDatas[i].curve
);
}
}
}
}
}
}
etc
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Animation spins wildly after completed 0 Answers
change animation name in inspector 2 Answers
Animation component in Unity 4.3 doesn't work? 2 Answers
How can I reassign animation curves to play on a child object (instead of through parent)? 1 Answer