using UnityEngine; using UnityEditor; public class ObjectNameModifier : EditorWindow { private string prefixText = string.Empty; private string suffixText = string.Empty; [MenuItem("Tools/Object Name Modifier")] public static void ShowWindow() { GetWindow("Object Name Modifier"); } private void OnGUI() { GUILayout.Label("Modify Object Names", EditorStyles.boldLabel); // Prefix Text 입력 prefixText = EditorGUILayout.TextField("Prefix", prefixText); // Suffix Text 입력 suffixText = EditorGUILayout.TextField("Suffix", suffixText); GUILayout.Space(10); // Prefix와 Suffix 추가 버튼 if (GUILayout.Button("Apply Prefix and Suffix")) { ApplyPrefixAndSuffix(); } GUILayout.Space(10); // 문자열 앞/뒤 한 글자씩 제거 if (GUILayout.Button("Remove First Character")) { RemoveFirstCharacter(); } if (GUILayout.Button("Remove Last Character")) { RemoveLastCharacter(); } GUILayout.Space(10); // 빈칸을 _로 변경 if (GUILayout.Button("Replace Spaces with Underscores")) { ReplaceSpacesWithUnderscores(); } } // Prefix와 Suffix를 적용하는 메서드 void ApplyPrefixAndSuffix() { foreach (GameObject obj in Selection.gameObjects) { Undo.RecordObject(obj, "Change Object Name"); obj.name = prefixText + obj.name + suffixText; } } // 첫 글자를 제거하는 메서드 void RemoveFirstCharacter() { foreach (GameObject obj in Selection.gameObjects) { if (obj.name.Length > 0) { Undo.RecordObject(obj, "Remove First Character"); obj.name = obj.name.Substring(1); } } } // 마지막 글자를 제거하는 메서드 void RemoveLastCharacter() { foreach (GameObject obj in Selection.gameObjects) { if (obj.name.Length > 0) { Undo.RecordObject(obj, "Remove Last Character"); obj.name = obj.name.Substring(0, obj.name.Length - 1); } } } // 빈칸을 _로 변경하는 메서드 void ReplaceSpacesWithUnderscores() { foreach (GameObject obj in Selection.gameObjects) { Undo.RecordObject(obj, "Replace Spaces"); obj.name = obj.name.Replace(" ", "_"); } } }