113 lines
3.8 KiB
C#
113 lines
3.8 KiB
C#
using System.Collections.Generic;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
public class BlendShapeRenamer : EditorWindow
|
|
{
|
|
private SkinnedMeshRenderer targetMeshRenderer;
|
|
private Dictionary<int, string> newNames;
|
|
private Vector2 scrollPos; // 스크롤 위치 저장 변수
|
|
private bool hasChanges = false;
|
|
|
|
[MenuItem("Tools/BlendShape Renamer")]
|
|
public static void ShowWindow()
|
|
{
|
|
GetWindow<BlendShapeRenamer>("BlendShape Renamer");
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
GUILayout.Label("Rename BlendShapes", EditorStyles.boldLabel);
|
|
|
|
// 대상 SkinnedMeshRenderer 오브젝트를 선택할 수 있는 필드
|
|
targetMeshRenderer = (SkinnedMeshRenderer)EditorGUILayout.ObjectField("Face Object", targetMeshRenderer, typeof(SkinnedMeshRenderer), true);
|
|
|
|
if (targetMeshRenderer != null)
|
|
{
|
|
Mesh mesh = targetMeshRenderer.sharedMesh;
|
|
if (mesh != null)
|
|
{
|
|
// BlendShape 이름이 초기화되지 않았거나 BlendShape 개수가 변한 경우 이름 초기화
|
|
if (newNames == null || newNames.Count != mesh.blendShapeCount)
|
|
{
|
|
InitializeNames(mesh);
|
|
}
|
|
|
|
EditorGUILayout.Space();
|
|
EditorGUILayout.LabelField("BlendShape Names", EditorStyles.boldLabel);
|
|
|
|
// 스크롤 가능 영역 설정
|
|
scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Height(300)); // 300은 스크롤 뷰의 높이
|
|
|
|
for (int i = 0; i < mesh.blendShapeCount; i++)
|
|
{
|
|
EditorGUILayout.BeginHorizontal();
|
|
EditorGUILayout.LabelField(mesh.GetBlendShapeName(i), GUILayout.MaxWidth(200));
|
|
newNames[i] = EditorGUILayout.TextField(newNames[i]);
|
|
EditorGUILayout.EndHorizontal();
|
|
}
|
|
|
|
EditorGUILayout.EndScrollView(); // 스크롤 뷰 끝
|
|
|
|
EditorGUILayout.Space();
|
|
if (GUILayout.Button("Rename"))
|
|
{
|
|
ApplyRenaming(mesh);
|
|
}
|
|
|
|
// Undo 버튼 추가
|
|
if (hasChanges && GUILayout.Button("Undo Last Change"))
|
|
{
|
|
Undo.PerformUndo();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
EditorGUILayout.HelpBox("The selected object does not have a valid mesh.", MessageType.Warning);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
EditorGUILayout.HelpBox("Please assign a SkinnedMeshRenderer object.", MessageType.Info);
|
|
}
|
|
}
|
|
|
|
// BlendShape 이름 초기화
|
|
private void InitializeNames(Mesh mesh)
|
|
{
|
|
newNames = new Dictionary<int, string>();
|
|
for (int i = 0; i < mesh.blendShapeCount; i++)
|
|
{
|
|
newNames[i] = mesh.GetBlendShapeName(i);
|
|
}
|
|
}
|
|
|
|
// 이름 적용 로직
|
|
private void ApplyRenaming(Mesh mesh)
|
|
{
|
|
Undo.RecordObject(mesh, "Rename BlendShapes");
|
|
|
|
for (int i = 0; i < mesh.blendShapeCount; i++)
|
|
{
|
|
string oldName = mesh.GetBlendShapeName(i);
|
|
string newName = newNames[i];
|
|
|
|
if (oldName != newName)
|
|
{
|
|
RenameBlendShape(mesh, i, newName);
|
|
}
|
|
}
|
|
|
|
hasChanges = true;
|
|
AssetDatabase.SaveAssets();
|
|
EditorUtility.SetDirty(mesh);
|
|
}
|
|
|
|
// BlendShape 이름을 변경하는 로직 (실제 구현은 메시 시스템에 따라 다름)
|
|
private void RenameBlendShape(Mesh mesh, int index, string newName)
|
|
{
|
|
// 메시의 BlendShape 이름을 실제로 변경하는 로직을 구현할 수 있습니다.
|
|
Debug.Log($"Renaming BlendShape {index} from '{mesh.GetBlendShapeName(index)}' to '{newName}'");
|
|
}
|
|
}
|