ClientServer/Client/Assets/Scripts/Util/AnimMixamorigCleaner.cs
TG9six 03a642d635 first push
first push
2025-09-06 17:17:39 +04:00

92 lines
2.5 KiB
C#

#if UNITY_EDITOR
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System.IO;
public class AnimBoneRenamer : EditorWindow
{
private List<AnimationClip> clips = new List<AnimationClip>();
private Vector2 scrollPos;
private string fromText = "mixamorig:";
private string toText = "";
[MenuItem("Tools/Anim Bone Renamer (List)")]
public static void ShowWindow()
{
GetWindow<AnimBoneRenamer>("Anim Bone Renamer (List)");
}
private void OnGUI()
{
GUILayout.Label("Replace Bone Names in Selected Animations", EditorStyles.boldLabel);
fromText = EditorGUILayout.TextField("Find", fromText);
toText = EditorGUILayout.TextField("Replace With", toText);
EditorGUILayout.Space();
EditorGUILayout.LabelField("Animation Clips", EditorStyles.boldLabel);
scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Height(200));
for (int i = 0; i < clips.Count; i++)
{
EditorGUILayout.BeginHorizontal();
clips[i] = (AnimationClip)EditorGUILayout.ObjectField(clips[i], typeof(AnimationClip), false);
if (GUILayout.Button("X", GUILayout.Width(20)))
{
clips.RemoveAt(i);
i--;
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndScrollView();
if (GUILayout.Button("Add Animation Clip"))
{
clips.Add(null);
}
EditorGUILayout.Space();
if (GUILayout.Button("Process All"))
{
ProcessAnimations();
}
}
private void ProcessAnimations()
{
int changed = 0;
foreach (var clip in clips)
{
if (clip == null) continue;
string path = AssetDatabase.GetAssetPath(clip);
if (!path.EndsWith(".anim"))
{
Debug.LogWarning($"Skipped: {clip.name} (not a .anim file)");
continue;
}
string fullPath = Path.Combine(Directory.GetCurrentDirectory(), path);
string content = File.ReadAllText(fullPath);
if (content.Contains(fromText))
{
content = content.Replace(fromText, toText);
File.WriteAllText(fullPath, content);
changed++;
Debug.Log($"Updated: {path}");
}
}
AssetDatabase.Refresh();
Debug.Log($"✅ Completed: {changed} animation(s) updated.");
}
}
#endif