Skip to content

Instantly share code, notes, and snippets.

@q8f13
Created July 16, 2019 05:42
Show Gist options
  • Save q8f13/f5266841aee7c212f42a0dde571df954 to your computer and use it in GitHub Desktop.
Save q8f13/f5266841aee7c212f42a0dde571df954 to your computer and use it in GitHub Desktop.
For convenient of renaming animation clips from fbx files
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class MixamoTools : EditorWindow
{
private static MixamoTools _window;
private Object[] _selectedAssets;
Vector2 scrollPos;
private void OnGUI() {
_selectedAssets = Selection.objects;
EditorGUILayout.BeginVertical();
GUILayout.Label("Selected Models");
if(_selectedAssets != null && _selectedAssets.Length > 0)
{
scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false, GUILayout.Height(150));
foreach(Object o in _selectedAssets)
{
EditorGUILayout.ObjectField(o, typeof(Object));
}
EditorGUILayout.EndScrollView();
}
EditorGUILayout.Separator();
if(GUILayout.Button("Change AnimationClip name to filename"))
{
ModelImporter mi = null;
// AnimationUtility.GetAnimationClips()
foreach(Object o in _selectedAssets)
{
string path = AssetDatabase.GetAssetPath(o);
int last_slash = path.LastIndexOf('/');
int last_dot = path.LastIndexOf('.');
string filename = path.Substring(last_slash + 1, last_dot - last_slash - 1);
filename = filename.Replace(' ', '_');
mi = ModelImporter.GetAtPath(path) as ModelImporter;
ModelImporterClipAnimation[] clips = new ModelImporterClipAnimation[mi.defaultClipAnimations.Length];
clips[0] = mi.defaultClipAnimations[0];
clips[0].name = filename;
mi.clipAnimations = clips;
mi.SaveAndReimport();
}
}
EditorGUILayout.EndVertical();
// _window =
}
[MenuItem("Tools/MixamoTools")]
static void OpenWindow()
{
if(_window == null)
{
_window = GetWindow<MixamoTools>();
_window.titleContent = new GUIContent("Mixamo Tools");
}
_window.Show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment