94 lines
3.0 KiB
C#
94 lines
3.0 KiB
C#
#if UNITY_EDITOR
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Bitd
|
|
{
|
|
public class DduDda : EditorWindow
|
|
{
|
|
private GameObject gameObject1;
|
|
private GameObject gameObject2;
|
|
private string suffix = string.Empty;
|
|
private bool exceptBreast = false;
|
|
|
|
[MenuItem("Bitd/뜌땨 v16", false, 1)]
|
|
public static void ShowWindow()
|
|
{
|
|
GetWindow<DduDda>("뜌뜌땨?뜌?");
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
GUILayout.Label("뜌뜌땨땨", EditorStyles.boldLabel);
|
|
|
|
gameObject1 = (GameObject)EditorGUILayout.ObjectField("원본 아마추어", gameObject1, typeof(GameObject), true);
|
|
gameObject2 = (GameObject)EditorGUILayout.ObjectField("의상의 아마추어", gameObject2, typeof(GameObject), true);
|
|
|
|
suffix = EditorGUILayout.TextField("뒤에 붙일 문구", suffix);
|
|
exceptBreast = EditorGUILayout.Toggle("가슴본은 넣지 말까요?", exceptBreast);
|
|
|
|
if (GUILayout.Button("병합하기"))
|
|
{
|
|
MergeGameObjects();
|
|
}
|
|
}
|
|
|
|
private void MergeGameObjects()
|
|
{
|
|
if (gameObject1 == null || gameObject2 == null)
|
|
{
|
|
Debug.LogWarning("두 개 다 제대로 넣어주세요.");
|
|
return;
|
|
}
|
|
|
|
Undo.IncrementCurrentGroup();
|
|
int undoGroup = Undo.GetCurrentGroup();
|
|
|
|
List<GameObject> children2 = GetAllChildren(gameObject2);
|
|
List<GameObject> children1 = GetAllChildren(gameObject1);
|
|
|
|
foreach (GameObject child2 in children2)
|
|
{
|
|
bool isBreast = child2.name.Contains("breast") || child2.name.Contains("Breast");
|
|
|
|
if (!(exceptBreast && isBreast))
|
|
{
|
|
foreach (GameObject child1 in children1)
|
|
{
|
|
if (child1.name == child2.name)
|
|
{
|
|
// 이름이 같은 경우, child2를 child1의 자식으로 이동
|
|
Undo.SetTransformParent(child2.transform, child1.transform, "Merge GameObjects");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 모든 child2 오브젝트에 접미사 추가
|
|
Undo.RecordObject(child2, "Rename GameObject");
|
|
child2.name += suffix;
|
|
}
|
|
|
|
// Undo 그룹 종료 및 병합
|
|
Undo.CollapseUndoOperations(undoGroup);
|
|
|
|
gameObject2 = null;
|
|
|
|
Debug.Log("Merging completed.");
|
|
}
|
|
|
|
private List<GameObject> GetAllChildren(GameObject parent)
|
|
{
|
|
List<GameObject> children = new List<GameObject>();
|
|
foreach (Transform child in parent.transform)
|
|
{
|
|
children.Add(child.gameObject);
|
|
children.AddRange(GetAllChildren(child.gameObject));
|
|
}
|
|
return children;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif |