Last active
June 11, 2023 12:23
-
-
Save somedeveloper00/5b81c67bcd7c8b3f2484e8166e2a7a8d to your computer and use it in GitHub Desktop.
Rename animation clips
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
#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 |
Author
somedeveloper00
commented
Jun 11, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment