I would like to add a context menu option for imported .FBX files. I previously had the same functionality in the AssetImporter, but I don’t want this functionality to happen for all .FBXs imported. I don’t want it to be automatic.
The specific functionality is just that I want to set the .FBX’s animation clips’ masks to ‘create from this model’ and set the avatar mask to every child bone.
Here’s the method I used in the Asset Importer:
/// <summary>
/// Automatically set this model importer's mask type to 'CreateFromThisModel' and set the mask
/// to the entire hierarchy.
/// </summary>
public static bool CreateMaskFromThisModel(this ModelImporter modelImporter, GameObject model)
{
bool changed = false;
ModelImporterClipAnimation[] clips = modelImporter.clipAnimations;
if (clips == null || clips.Length == 0)
clips = modelImporter.defaultClipAnimations;
ModelImporterClipAnimation[] newAnims = new ModelImporterClipAnimation[clips.Length];
for (int i = 0; i < clips.Length; i++)
{
if (clips*.maskType != ClipAnimationMaskType.CreateFromThisModel)*
{
newAnims = clips*;*
newAnims*.maskType = ClipAnimationMaskType.CreateFromThisModel;*
changed = true;
}
}
AvatarMask mask = new AvatarMask();
mask.AddTransformPath(model.transform, true);
for (int i = 0; i < clips.Length; i++)
{
if (clips_.maskSource == null || clips*.maskSource.transformCount != mask.transformCount)
{_
_clips.ConfigureClipFromMask(mask);
changed = true;
}
}*_
modelImporter.clipAnimations = clips;
return changed;
}
----------
This works. However, I seem to have no way to access the model importer after the import, at will. This is as far as I’ve gotten for my context menu.
[MenuItem(“Assets/Create Mask From This Model”, isValidateFunction: true)]
private static bool CheckIfFBX()
{
if (Selection.gameObjects.Length == 0)
return false;
for (int i = 0; i < Selection.gameObjects.Length; i++)
if (!AssetDatabase.GetAssetPath(Selection.gameObjects*).ToLowerInvariant().EndsWith(“.fbx”))*
return false;
return true;
}
[MenuItem(“Assets/Create Mask From This Model”)]
private static void CreateMaskFromThisModel()
{
for (int i = 0; i < Selection.gameObjects.Length; i++)
{
// get importer, clips, avatar mask, anything?
}
}