少年修仙传客户端基础资源
dabaoji
2025-06-09 8ee0256378cbf5dbc9d76ed10b60b65a844ef4dd
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using UnityEngine;
using UnityEditor;
using System;
using qtools.qhierarchy.pcomponent.pbase;
using qtools.qhierarchy.pdata;
using qtools.qhierarchy.phierarchy;
using qtools.qhierarchy.phelper;
using System.Collections.Generic;
using System.Collections;
 
namespace qtools.qhierarchy.pcomponent
{
    public class QTreeMapComponent: QBaseComponent
    {
        // CONST
        private const float TREE_STEP_WIDTH  = 14.0f;
        
        // PRIVATE
        private Texture2D treeMapLevelTexture;       
        private Texture2D treeMapLevel4Texture;       
        private Texture2D treeMapCurrentTexture;   
        private Texture2D treeMapLastTexture;
        private Texture2D treeMapObjectTexture;    
        private bool enhanced;
        private bool transparentBackground;
        private Color backgroundColor;
        private Color treeMapColor;
        
        // CONSTRUCTOR
        public QTreeMapComponent()
        { 
 
            treeMapLevelTexture   = QResources.getInstance().getTexture(QTexture.QTreeMapLevel);
            treeMapLevel4Texture  = QResources.getInstance().getTexture(QTexture.QTreeMapLevel4);
            treeMapCurrentTexture = QResources.getInstance().getTexture(QTexture.QTreeMapCurrent);
            #if UNITY_2018_3_OR_NEWER
                treeMapObjectTexture = QResources.getInstance().getTexture(QTexture.QTreeMapLine);
            #else
                treeMapObjectTexture  = QResources.getInstance().getTexture(QTexture.QTreeMapObject);
            #endif
            treeMapLastTexture    = QResources.getInstance().getTexture(QTexture.QTreeMapLast);
            
            rect.width  = 14;
            rect.height = 16;
            
            showComponentDuringPlayMode = true;
 
            QSettings.getInstance().addEventListener(QSetting.AdditionalBackgroundColor, settingsChanged);
            QSettings.getInstance().addEventListener(QSetting.TreeMapShow           , settingsChanged);
            QSettings.getInstance().addEventListener(QSetting.TreeMapColor          , settingsChanged);
            QSettings.getInstance().addEventListener(QSetting.TreeMapEnhanced       , settingsChanged);
            QSettings.getInstance().addEventListener(QSetting.TreeMapTransparentBackground, settingsChanged);
            settingsChanged();
        }
        
        // PRIVATE
        private void settingsChanged() {
            backgroundColor     = QSettings.getInstance().getColor(QSetting.AdditionalBackgroundColor);
            enabled             = QSettings.getInstance().get<bool>(QSetting.TreeMapShow);
            treeMapColor        = QSettings.getInstance().getColor(QSetting.TreeMapColor);
            enhanced            = QSettings.getInstance().get<bool>(QSetting.TreeMapEnhanced);
            transparentBackground = QSettings.getInstance().get<bool>(QSetting.TreeMapTransparentBackground);
        }
        
        // DRAW
        public override QLayoutStatus layout(GameObject gameObject, QObjectList objectList, Rect selectionRect, ref Rect curRect, float maxWidth)
        {
            rect.y = selectionRect.y;
            
            if (!transparentBackground) 
            {
                rect.x = 0;
                
                rect.width = selectionRect.x - 14;
                EditorGUI.DrawRect(rect, backgroundColor);
                rect.width = 14;
            }
 
            return QLayoutStatus.Success;
        }
 
        public override void draw(GameObject gameObject, QObjectList objectList, Rect selectionRect)
        {
            int childCount = gameObject.transform.childCount;
            int level = Mathf.RoundToInt(selectionRect.x / 14.0f);
 
            if (enhanced)
            {
                Transform gameObjectTransform = gameObject.transform;
                Transform parentTransform = null;
 
                for (int i = 0, j = level - 1; j >= 0; i++, j--)
                {
                    rect.x = 14 * j;
                    if (i == 0)
                    {
                        if (childCount == 0) {
                            #if UNITY_2018_3_OR_NEWER
                                QColorUtils.setColor(treeMapColor);
                            #endif
                            GUI.DrawTexture(rect, treeMapObjectTexture);
                        }
                        gameObjectTransform = gameObject.transform;
                    }
                    else if (i == 1)
                    {
                        QColorUtils.setColor(treeMapColor);
                        if (parentTransform == null) {
                            if (gameObjectTransform.GetSiblingIndex() == gameObject.scene.rootCount - 1) {
                                GUI.DrawTexture(rect, treeMapLastTexture);
                            } else {
                                GUI.DrawTexture(rect, treeMapCurrentTexture);
                            }
                        } else if (gameObjectTransform.GetSiblingIndex() == parentTransform.childCount - 1) {
                            GUI.DrawTexture(rect, treeMapLastTexture);
                        } else {
                            GUI.DrawTexture(rect, treeMapCurrentTexture);
                        }
                        gameObjectTransform = parentTransform;
                    }
                    else
                    {
                        if (parentTransform == null) {
                            if (gameObjectTransform.GetSiblingIndex() != gameObject.scene.rootCount - 1)
                                GUI.DrawTexture(rect, treeMapLevelTexture);
                        } else if (gameObjectTransform.GetSiblingIndex() != parentTransform.childCount - 1)
                            GUI.DrawTexture(rect, treeMapLevelTexture);
 
                        gameObjectTransform = parentTransform;                       
                    }
                    if (gameObjectTransform != null) 
                        parentTransform = gameObjectTransform.parent;
                    else
                        break;
                }
                QColorUtils.clearColor();
            }
            else
            {
                for (int i = 0, j = level - 1; j >= 0; i++, j--)
                {
                    rect.x = 14 * j;
                    if (i == 0)
                    {
                        if (childCount > 0)
                            continue;
                        else {
                            #if UNITY_2018_3_OR_NEWER
                                QColorUtils.setColor(treeMapColor);
                            #endif
                            GUI.DrawTexture(rect, treeMapObjectTexture);
                        }
                    }
                    else if (i == 1)
                    {
                        QColorUtils.setColor(treeMapColor);
                        GUI.DrawTexture(rect, treeMapCurrentTexture);
                    }
                    else
                    {
                        rect.width = 14 * 4;
                        rect.x -= 14 * 3;
                        j -= 3;
                        GUI.DrawTexture(rect, treeMapLevel4Texture);
                        rect.width = 14;
                    }
                }
                QColorUtils.clearColor();
            }
        }
    }
}