열차 목업의 내부 확인용 프로젝트
smchoi
2024-07-24 ff74c0073046f0e086eb7d355950bda39937c92c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
 
public class SelectedAllHideUtil : EditorWindow
{
    List<GameObject> 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<GameObject>();
        }
 
        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<Transform>();
        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<Transform>(true);
        for (int i = 0; i < gos.Length; i++)
        {
            if (!gos[i].gameObject.activeSelf)
            {
                AddHideObject(gos[i].gameObject);
            }
        }
    }
}