Is it possible?
I changed every animation’s MaskType from ‘Copy From Other Mask’ to ‘Create From This Model’ by script. And I got the button ‘Fix Mask’ on the inspector.
Because I have a lot of animations, I want to call ‘Fix Mask’ methods.
Is it possible?
I changed every animation’s MaskType from ‘Copy From Other Mask’ to ‘Create From This Model’ by script. And I got the button ‘Fix Mask’ on the inspector.
Because I have a lot of animations, I want to call ‘Fix Mask’ methods.
Unfortunately no, the call is not available from the API.
you can use this script to automatically fix all masks, I’ve tested it in Unity 4.7, it assumes the default behavior of using “Mask Definition: Create From This Model” with all transforms selected.
[
//saves you from agonizing manual clicking "Fix Mask" on each user-created clip,
//when you have updated/edited the original FBX changing the skeleton hierarchy
//drop this in your Scripts/Editor folder,
//select FBX's and right click context menu Fix Animation Masks
//tested on Unity 4.7
//minor update, sets all transforms of the avatarMask to active (assuming you are just using 'Mask Definition Create From This Model' with all transforms active (Default behavior)
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using System;
using System.Reflection;
public class FixMask
{
[MenuItem("Assets/Fix Animation Masks")]
private static void Init()
{
UnityEngine.Object[] selection = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
foreach( UnityEngine.Object obj in selection )
{
string path = AssetDatabase.GetAssetPath( obj );
ModelImporter mi = AssetImporter.GetAtPath(path) as ModelImporter;
Type modelImporterType = typeof(ModelImporter);
MethodInfo updateTransformMaskMethodInfo = modelImporterType.GetMethod("UpdateTransformMask", BindingFlags.NonPublic | BindingFlags.Static);
ModelImporterClipAnimation[] clipAnimations = mi.clipAnimations;
SerializedObject so = new SerializedObject(mi);
SerializedProperty clips = so.FindProperty("m_ClipAnimations");
AvatarMask avatarMask = new AvatarMask();
avatarMask.transformCount = mi.transformPaths.Length;
for( int i=0; i<mi.transformPaths.Length; i++ )
{
avatarMask.SetTransformPath(i,mi.transformPaths[i]);
avatarMask.SetTransformActive(i,true);
}
for( int i=0; i<clipAnimations.Length; i++ )
{
SerializedProperty transformMaskProperty = clips.GetArrayElementAtIndex(i).FindPropertyRelative("transformMask");
updateTransformMaskMethodInfo.Invoke(mi, new System.Object[]{avatarMask, transformMaskProperty});
}
so.ApplyModifiedProperties();
AssetDatabase.ImportAsset(path);
}
}
}