Last active
September 27, 2024 08:36
-
-
Save mitay-walle/c6ff675d7ff4f66db244c84ae60c62fc to your computer and use it in GitHub Desktop.
Unity3d Menu Item to rename "Mixamo" animations to same as file-name
This file contains hidden or 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
[MenuItem("Assets/Rename Animations")] | |
private static void RenameAnimations() | |
{ | |
Selection.objects.Where(EditorUtility.IsPersistent) | |
.Select(AssetDatabase.GetAssetPath) | |
.ForEach(path => | |
{ | |
string fileName = Path.GetFileNameWithoutExtension(path); | |
ModelImporter importer = (ModelImporter)AssetImporter.GetAtPath(path); | |
RenameAndImport(importer, fileName); | |
}); | |
AssetDatabase.SaveAssets(); | |
AssetDatabase.Refresh(); | |
} | |
private static void RenameAndImport(ModelImporter modelImporter, string name) | |
{ | |
ModelImporterClipAnimation[] clipAnimations = modelImporter.defaultClipAnimations; | |
for (int i = 0; i < clipAnimations.Length; i++) | |
{ | |
clipAnimations[i].name = name; | |
} | |
modelImporter.clipAnimations = clipAnimations; | |
modelImporter.SaveAndReimport(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment