using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; public class SelectedAllHideUtil : EditorWindow { List hideObjects; public int Count { get { return hideObjects != null ? hideObjects.Count : 0; } } [MenuItem("MaprexUtil/Hide Util")] static void Init() { SelectedAllHideUtil window = (SelectedAllHideUtil)EditorWindow.GetWindow(typeof(SelectedAllHideUtil)); window.Show(); } void Clear() { if (hideObjects != null) { hideObjects.Clear(); } } void AddHideObject(GameObject go) { if (hideObjects == null) { hideObjects = new List(); } hideObjects.Add(go); } GameObject Find(string name) { if (hideObjects != null) { return hideObjects.Find(o => o.name == name); } return null; } void OnGUI() { GUILayout.Label(string.Format("Mesh Vertex Count: {0}", Count)); // 선택된 오브젝트 서브메쉬 분리 if (GUILayout.Button("Load Hide Objects All")) { Clear(); GameObject[] selectObjs = Selection.gameObjects; if (selectObjs != null && selectObjs.Length > 0) { for (int i = 0; i < selectObjs.Length; i++) { LoadHideObjectsAll(selectObjs[i]); } } else { Debug.LogError("선택된 오브젝트가 없습니다."); } } if (GUILayout.Button("Set Hide Objects All")) { GameObject selectObj = Selection.activeGameObject; if (selectObj != null) { SetHideObjectsAll(selectObj); } else { Debug.LogError("선택된 오브젝트가 없습니다."); } } } void SetHideObjectsAll(GameObject go) { int count = 0; Transform[] gos = go.GetComponentsInChildren(); for (int i = 0; i < gos.Length; i++) { GameObject findObj = Find(gos[i].name); if (findObj != null) { Debug.Log(findObj); gos[i].gameObject.SetActive(false); count++; } else { Debug.LogWarningFormat("Not found object: {0}", gos[i].name); } } Debug.LogFormat("Set Complete {0}/{1}", count, gos.Length); } void LoadHideObjectsAll(GameObject go) { Transform[] gos = go.GetComponentsInChildren(true); for (int i = 0; i < gos.Length; i++) { if (!gos[i].gameObject.activeSelf) { AddHideObject(gos[i].gameObject); } } } }