Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement