Created
May 4, 2016 01:18
-
-
Save whaison/aa448a2c6c6228c10b34862f3bdc1feb to your computer and use it in GitHub Desktop.
FixMask.cs (Unity5.3.4p3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 | |
//reImporot Foloder | |
//tested on Unity 5.3.4p3 | |
//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; | |
using UnityEditor.Animations; | |
using System.Collections; | |
using System.IO; | |
public static class FixMask | |
{ | |
[MenuItem("Tools/Motion/FixMask/Fix Animation Masks")] | |
private static void FBXFixMask() | |
{ | |
UnityEngine.Object[] selection = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets); | |
foreach( UnityEngine.Object obj in selection ) | |
{ | |
string path = AssetDatabase.GetAssetPath( obj ); | |
Debug.Log ("Tool path ="+ path); | |
FBXFixMaskAtPath (path); | |
} | |
} | |
public static void FBXFixMaskAtPath(string path){ | |
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"); | |
UnityEditor.Animations.AvatarMask avatarMask = new UnityEditor.Animations.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); | |
} | |
} | |
/* | |
public class FBXModelImpoterSettingEditor : AssetPostprocessor | |
{ | |
/// <summary> | |
/// ディレクトリ直下のバンドル名 | |
/// </summary> | |
const string defaultBundeName = "default"; | |
const bool unitFolder = true; | |
/// <summary> | |
/// アセットバンドルに含めるアセットのベースパス | |
/// </summary> | |
public const string assetBundleBasePath = "Assets/AssetBundleData/unit/"; | |
/// <summary> | |
/// バンドルするファイルの拡張子 | |
/// </summary> | |
protected static string[] includeExtension = new string[] { | |
".fbx", | |
}; | |
//".shader", | |
public static void OnPostprocessAllAssets (string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetsPath) | |
{ | |
foreach (string path in importedAssets) { | |
Debug.Log ("OnPostprocess path ="+ path); | |
//FixMask.FBXFixMaskAtPath (path); | |
} | |
//foreach (string path in movedAssets) { | |
// SetAssetBundleName (path); | |
//} | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment