Skip to content

Instantly share code, notes, and snippets.

@somedeveloper00
Last active June 11, 2023 12:23
Show Gist options
  • Save somedeveloper00/5b81c67bcd7c8b3f2484e8166e2a7a8d to your computer and use it in GitHub Desktop.
Save somedeveloper00/5b81c67bcd7c8b3f2484e8166e2a7a8d to your computer and use it in GitHub Desktop.
Rename animation clips
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
public class SimpleAnimationClipRename : EditorWindow {
[MenuItem( "Window/AnimationClipSuperRename" )]
public static void ShowWindow() {
GetWindow<SimpleAnimationClipRename>( "AnimationClipSuperRename" );
}
public ModelImporter modelImporter;
public string find, replace;
void OnGUI() {
using (var check = new EditorGUI.ChangeCheckScope()) {
var obj = EditorGUILayout.ObjectField( "Model", modelImporter, typeof( Object ), false );
if (check.changed) {
modelImporter = AssetImporter.GetAtPath( AssetDatabase.GetAssetPath( obj ) ) as ModelImporter;
}
}
// show name of all clips
using (new GUILayout.VerticalScope( EditorStyles.helpBox )) {
if (modelImporter != null) {
var animationClips = modelImporter.clipAnimations;
foreach (var animationClip in animationClips) EditorGUILayout.LabelField( animationClip.name );
}
}
find = EditorGUILayout.TextField( "Find", find );
replace = EditorGUILayout.TextField( "Replace", replace );
// preview name of all clips after rename
using (new GUILayout.VerticalScope( EditorStyles.helpBox )) {
if (modelImporter != null) {
var animationClips = modelImporter.clipAnimations;
foreach (var animationClip in animationClips) {
var newName = find == replace ? animationClip.name : animationClip.name.Replace( find, replace );
EditorGUILayout.LabelField( newName );
}
}
}
// button for action
if (GUILayout.Button( "Rename", GUILayout.Height( 30 ) )) {
Rename();
}
}
void Rename() {
var animationClips = modelImporter.clipAnimations;
foreach (var animationClip in animationClips) {
animationClip.name = animationClip.name.Replace( find, replace );
}
// apply
modelImporter.clipAnimations = animationClips;
modelImporter.SaveAndReimport();
}
}
#endif
@somedeveloper00
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment