+ 캐논의 방향 반전 버그 수정 + 캐논의 속도 고정 타입 사용 시, 목표 지점이 바뀌는 버그 수정 + 캐논 차징 도중 LineRenderer, Maker가 사라지지 않던 버그 수정 + 캐논 인스펙터창 수정 + 02.Ocean 씬 취합 과정에서 승회님 Image, material 수정, Props들 Prefab화 + ShipPlayer, PirateShip 부력 옵션 및 Rigidbody 수정 + Tools/Rename Child Objects Window을 통해서 자식들의 이름 변경 기능 추가
112 lines
3.7 KiB
C#
112 lines
3.7 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.Linq;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace BlueWaterProject
|
|
{
|
|
public class HierarchySorter : EditorWindow
|
|
{
|
|
string baseName = ""; // 기본 이름
|
|
int numberingStyle = 1; // 숫자 스타일
|
|
|
|
[MenuItem("Tools/Sort Children by Name")]
|
|
private static void SortChildrenByName()
|
|
{
|
|
if (Selection.activeTransform != null)
|
|
{
|
|
Undo.RecordObject(Selection.activeTransform.gameObject, "Sort Children by Name");
|
|
|
|
var children = Selection.activeTransform.Cast<Transform>().OrderBy(t => t.name).ToList();
|
|
for (var i = 0; i < children.Count; i++)
|
|
{
|
|
children[i].SetSiblingIndex(i);
|
|
}
|
|
|
|
EditorUtility.SetDirty(Selection.activeTransform.gameObject);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("No object selected in the hierarchy");
|
|
}
|
|
}
|
|
|
|
[MenuItem("Tools/Sort Children of Selected Objects by Name")]
|
|
private static void SortChildrenOfSelectedObjectsByName()
|
|
{
|
|
foreach (var parentTransform in Selection.transforms)
|
|
{
|
|
Undo.RecordObject(parentTransform.gameObject, "Sort Children by Name");
|
|
|
|
var children = parentTransform.Cast<Transform>().OrderBy(t => t.name).ToList();
|
|
for (var i = 0; i < children.Count; i++)
|
|
{
|
|
children[i].SetSiblingIndex(i);
|
|
}
|
|
|
|
EditorUtility.SetDirty(parentTransform.gameObject);
|
|
}
|
|
}
|
|
|
|
[MenuItem("Tools/Rename Child Objects Window")]
|
|
public static void ShowWindow()
|
|
{
|
|
GetWindow<HierarchySorter>("Rename Child Objects");
|
|
}
|
|
|
|
void OnGUI()
|
|
{
|
|
GUILayout.Label("Base Settings", EditorStyles.boldLabel);
|
|
baseName = EditorGUILayout.TextField("Base Name", baseName);
|
|
numberingStyle = EditorGUILayout.IntSlider("Numbering Style", numberingStyle, 1, 3);
|
|
|
|
if (GUILayout.Button("Rename Children"))
|
|
{
|
|
RenameChildren();
|
|
}
|
|
}
|
|
|
|
void RenameChildren()
|
|
{
|
|
GameObject selectedObject = Selection.activeGameObject;
|
|
|
|
if (selectedObject != null)
|
|
{
|
|
Undo.SetCurrentGroupName("Rename Child Objects");
|
|
int group = Undo.GetCurrentGroup();
|
|
|
|
int startNumber = 1; // 시작 숫자 설정
|
|
|
|
for (int i = 0; i < selectedObject.transform.childCount; i++)
|
|
{
|
|
GameObject child = selectedObject.transform.GetChild(i).gameObject;
|
|
Undo.RecordObject(child, "Rename Child");
|
|
|
|
string newName = baseName + " (" + GetFormattedNumber(startNumber + i, numberingStyle) + ")";
|
|
child.name = newName;
|
|
}
|
|
|
|
Undo.CollapseUndoOperations(group);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("선택된 오브젝트가 없습니다.");
|
|
}
|
|
}
|
|
|
|
private static string GetFormattedNumber(int number, int style)
|
|
{
|
|
switch (style)
|
|
{
|
|
case 1: // (1), (2), (3), ...
|
|
return number.ToString();
|
|
case 2: // (01), (02), (03), ...
|
|
return number.ToString("D2");
|
|
case 3: // (001), (002), (003), ...
|
|
return number.ToString("D3");
|
|
default:
|
|
return number.ToString();
|
|
}
|
|
}
|
|
}
|
|
} |