少年修仙传客户端基础资源
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
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using qtools.qhierarchy.pcomponent.pbase;
using qtools.qhierarchy.pdata;
using qtools.qhierarchy.phelper;
 
namespace qtools.qhierarchy.pcomponent
{
    public class QColorComponent: QBaseComponent
    {
        // PRIVATE
        private Texture2D colorTexture;
        private Color backgroundColor;
 
        // CONSTRUCTOR
        public QColorComponent()
        {
            colorTexture = QResources.getInstance().getTexture(QTexture.QColorButton);
            backgroundColor = QResources.getInstance().getColor(QColor.Background);
 
            QSettings.getInstance().addEventListener(QSetting.ShowColorComponent              , settingsChanged);
            QSettings.getInstance().addEventListener(QSetting.ShowColorComponentDuringPlayMode, settingsChanged);
            settingsChanged();
        }
 
        // PRIVATE
        private void settingsChanged()
        {
            enabled = QSettings.getInstance().get<bool>(QSetting.ShowColorComponent);
            showComponentDuringPlayMode = QSettings.getInstance().get<bool>(QSetting.ShowColorComponentDuringPlayMode);
        }
 
        // LAYOUT
        public override void layout(GameObject gameObject, QObjectList objectList, ref Rect rect)
        {
            rect.x -= 9;
            rect.width = 9;
        }
 
        // DRAW
        public override void draw(GameObject gameObject, QObjectList objectList, Rect selectionRect, Rect curRect)
        {
            EditorGUI.DrawRect(curRect, backgroundColor);
            GUI.DrawTexture(curRect, colorTexture, ScaleMode.StretchToFill, true, 1);
 
            if (objectList != null)
            {
                curRect.x += 1;
                curRect.width = 5;
                curRect.height -= 1;
 
                Color newColor;
                if (objectList.gameObjectColor.TryGetValue(gameObject, out newColor))
                {
                    EditorGUI.DrawRect(curRect, newColor);
                }
            }
        }
 
        // EVENTS
        public override void eventHandler(GameObject gameObject, QObjectList objectList, Event currentEvent, Rect curRect)
        {
            if (currentEvent.isMouse && currentEvent.type == EventType.MouseDown && currentEvent.button == 0 && curRect.Contains(currentEvent.mousePosition))
            {
                if (currentEvent.type == EventType.MouseDown)
                {
                    Color color = QResources.getInstance().getColor(QColor.Background);
                    color.a = 0.1f;
 
                    if (objectList != null) objectList.gameObjectColor.TryGetValue(gameObject, out color);   
 
                    try 
                    {
                        PopupWindow.Show(curRect, new QColorPickerWindow(Selection.Contains(gameObject) ? Selection.gameObjects : new GameObject[] { gameObject }, colorSelectedHandler, colorRemovedHandler));
                    } 
                    catch 
                    {}
                }
                currentEvent.Use();
            }
        }
 
        // PRIVATE
        private void colorSelectedHandler(GameObject[] gameObjects, Color color)
        {
            for (int i = gameObjects.Length - 1; i >= 0; i--)
            {
                GameObject gameObject = gameObjects[i];
                QObjectList objectList = QObjectListManager.getInstance().getObjectList(gameObjects[i], true);
                Undo.RecordObject(objectList, "Color Changed");
                if (objectList.gameObjectColor.ContainsKey(gameObject))
                {
                    objectList.gameObjectColor[gameObject] = color;
                }
                else
                {
                    objectList.gameObjectColor.Add(gameObject, color);
                }                
            }
            EditorApplication.RepaintHierarchyWindow();
        }
 
        private void colorRemovedHandler(GameObject[] gameObjects)
        {
            for (int i = gameObjects.Length - 1; i >= 0; i--)
            {
                GameObject gameObject = gameObjects[i];
                QObjectList objectList = QObjectListManager.getInstance().getObjectList(gameObjects[i], true);
                if (objectList.gameObjectColor.ContainsKey(gameObject))                
                {
                    Undo.RecordObject(objectList, "Color Changed");
                    objectList.gameObjectColor.Remove(gameObject);                          
                }
            }
            EditorApplication.RepaintHierarchyWindow();
        }
    }
}