少年修仙传客户端基础资源
dabaoji
2023-11-13 0a23e1b83f8fda8ab9f9e32fe71c26c431faf63a
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;
using qtools.qhierarchy.pcomponent;
using qtools.qhierarchy.pcomponent.pbase;
using qtools.qhierarchy.pdata;
using qtools.qhierarchy.phelper;
using System.Reflection;
 
namespace qtools.qhierarchy.phierarchy
{
    public class QHierarchy
    {
        // PRIVATE
        private HashSet<int> errorHandled = new HashSet<int>();      
        private Dictionary<int, QBaseComponent> componentDictionary;          
        private List<QBaseComponent> preComponents;
        private List<QBaseComponent> orderedComponents;
        private List<QBaseComponent> postComponents;
        private bool hideIconsIfThereIsNoFreeSpace;
        private int indentation;
        private Texture2D trimIcon;
 
        // CONSTRUCTOR
        public QHierarchy ()
        {
            componentDictionary = new Dictionary<int, QBaseComponent>();
            componentDictionary.Add((int)QHierarchyComponentEnum.LockComponent             , new QLockComponent());
            componentDictionary.Add((int)QHierarchyComponentEnum.VisibilityComponent       , new QVisibilityComponent());
            componentDictionary.Add((int)QHierarchyComponentEnum.StaticComponent           , new QStaticComponent());
            componentDictionary.Add((int)QHierarchyComponentEnum.RendererComponent         , new QRendererComponent());
            componentDictionary.Add((int)QHierarchyComponentEnum.TagLayerComponent         , new QTagLayerComponent());
            componentDictionary.Add((int)QHierarchyComponentEnum.GameObjectIconComponent   , new QGameObjectIconComponent());
            componentDictionary.Add((int)QHierarchyComponentEnum.ErrorComponent            , new QErrorComponent());
            componentDictionary.Add((int)QHierarchyComponentEnum.TagIconComponent          , new QTagIconComponent());
            componentDictionary.Add((int)QHierarchyComponentEnum.ColorComponent            , new QColorComponent());
            componentDictionary.Add((int)QHierarchyComponentEnum.ComponentsComponent       , new QComponentsComponent());
            componentDictionary.Add((int)QHierarchyComponentEnum.ChildrenCountComponent    , new QChildrenCountComponent());
            componentDictionary.Add((int)QHierarchyComponentEnum.PrefabComponent           , new QPrefabComponent());
 
            preComponents = new List<QBaseComponent>();
            preComponents.Add(new QTreeMapComponent());
            preComponents.Add(new QMonoBehaviorIconComponent());
 
            orderedComponents = new List<QBaseComponent>();
 
            postComponents = new List<QBaseComponent>();
            postComponents.Add(new QSeparatorComponent());
 
            trimIcon = QResources.getInstance().getTexture(QTexture.QTrimIcon);
 
            QSettings.getInstance().addEventListener(QSetting.Identation                    , settingsChanged);
            QSettings.getInstance().addEventListener(QSetting.ComponentOrder                , settingsChanged);
            QSettings.getInstance().addEventListener(QSetting.HideIconsIfNotFit             , settingsChanged);
            settingsChanged();
        }
         
        // PRIVATE
        private void settingsChanged()
        {
            orderedComponents.Clear(); 
            string componentOrder = QSettings.getInstance().get<string>(QSetting.ComponentOrder);
            string[] componentIds = componentOrder.Split(';');
            if (componentIds.Length != QSettings.DEFAULT_ORDER_COUNT) 
            {
                QSettings.getInstance().set(QSetting.ComponentOrder, QSettings.DEFAULT_ORDER);
                componentIds = QSettings.DEFAULT_ORDER.Split(';');
            }
 
            for (int i = 0; i < componentIds.Length; i++)                
                orderedComponents.Add(componentDictionary[int.Parse(componentIds[i])]);
            orderedComponents.Add(componentDictionary[(int)QHierarchyComponentEnum.ComponentsComponent]);
 
            indentation = QSettings.getInstance().get<int>(QSetting.Identation);
            hideIconsIfThereIsNoFreeSpace = QSettings.getInstance().get<bool>(QSetting.HideIconsIfNotFit);
        }
 
        public void hierarchyWindowItemOnGUIHandler(int instanceId, Rect selectionRect)
        {
            try
            {
                GameObject gameObject = (GameObject)EditorUtility.InstanceIDToObject(instanceId);
                if (gameObject == null) return;
 
                Rect curRect = new Rect(selectionRect);
                curRect.width = 16;
                curRect.x += selectionRect.width - indentation;
 
                float gameObjectNameWidth = hideIconsIfThereIsNoFreeSpace ? GUI.skin.label.CalcSize(new GUIContent(gameObject.name)).x : 0;
 
                QObjectList objectList = QObjectListManager.getInstance().getObjectList(gameObject, false);
 
                drawComponents(preComponents    , selectionRect, ref curRect, gameObject, objectList);
                drawComponents(orderedComponents, selectionRect, ref curRect, gameObject, objectList, hideIconsIfThereIsNoFreeSpace, selectionRect.x + gameObjectNameWidth + 7);
                drawComponents(postComponents   , selectionRect, ref curRect, gameObject, objectList);
 
                errorHandled.Remove(instanceId);
            }
            catch (Exception exception)
            {
                if (errorHandled.Add(instanceId))
                {
                    Debug.LogError(exception.ToString());
                }
            }
        }
 
        private void drawComponents(List<QBaseComponent> components, Rect selectionRect, ref Rect curRect, GameObject gameObject, QObjectList objectList, bool trim = false, float minX = 50)
        {
            Rect rect = new Rect(curRect);
            if (Event.current.type == EventType.Repaint)
            {
                for (int i = 0, n = components.Count; i < n; i++)
                {
                    QBaseComponent component = components[i];
                    if (component.isEnabled())
                    {
                        component.layout(gameObject, objectList, ref rect);
                        if (trim && minX > rect.x)
                        {
                            rect.Set(curRect.x - 7, curRect.y, 7, 16);
                            GUI.DrawTexture(rect, trimIcon);
                            return;
                        }
                        component.draw(gameObject, objectList, selectionRect, rect);
                        curRect.Set(rect.x, rect.y, rect.width, rect.height);
                    }
                    else
                    {
                        component.disabledHandler(gameObject, objectList);
                    }
                }
            }
            else if (Event.current.isMouse)
            {
                for (int i = 0, n = components.Count; i < n; i++)
                {
                    QBaseComponent component = components[i];
                    if (component.isEnabled())
                    {
                        component.layout(gameObject, objectList, ref rect);
                        if (trim && minX > rect.x)
                        {
                            rect.Set(curRect.x - 7, curRect.y, 7, 16);
                            GUI.DrawTexture(rect, trimIcon);
                            return;
                        }
                        component.eventHandler(gameObject, objectList, Event.current, rect);
                        curRect.Set(rect.x, rect.y, rect.width, rect.height);
                    }
                }
            }
        }
    }
}