少年修仙传客户端基础资源
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
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 QPrefabComponent: QBaseComponent
    {
        // PRIVATE
        private Color activeColor;
        private Color inactiveColor;
        private Texture2D prefabTexture;
        private bool showPrefabConnectedIcon;
 
        // CONSTRUCTOR
        public QPrefabComponent()
        {
            rect.width = 9;
 
            prefabTexture = QResources.getInstance().getTexture(QTexture.QPrefabIcon);
 
            QSettings.getInstance().addEventListener(QSetting.PrefabShowBreakedPrefabsOnly  , settingsChanged);
            QSettings.getInstance().addEventListener(QSetting.PrefabShow                    , settingsChanged);
            QSettings.getInstance().addEventListener(QSetting.AdditionalActiveColor         , settingsChanged);
            QSettings.getInstance().addEventListener(QSetting.AdditionalInactiveColor       , settingsChanged);
            settingsChanged();
        }
        
        // PRIVATE
        private void settingsChanged()
        {
            showPrefabConnectedIcon = QSettings.getInstance().get<bool>(QSetting.PrefabShowBreakedPrefabsOnly);
            enabled                 = QSettings.getInstance().get<bool>(QSetting.PrefabShow);
            activeColor             = QSettings.getInstance().getColor(QSetting.AdditionalActiveColor);
            inactiveColor           = QSettings.getInstance().getColor(QSetting.AdditionalInactiveColor);
        }
 
        // DRAW
        public override QLayoutStatus layout(GameObject gameObject, QObjectList objectList, Rect selectionRect, ref Rect curRect, float maxWidth)
        {
            if (maxWidth < 9)
            {
                return QLayoutStatus.Failed;
            }
            else
            {
                curRect.x -= 9;
                rect.x = curRect.x;
                rect.y = curRect.y;
                return QLayoutStatus.Success;
            }
        }
        
        public override void draw(GameObject gameObject, QObjectList objectList, Rect selectionRect)
        {
            #if UNITY_2018_3_OR_NEWER
                PrefabInstanceStatus prefabStatus = PrefabUtility.GetPrefabInstanceStatus(gameObject);
                if (prefabStatus == PrefabInstanceStatus.MissingAsset ||
                    prefabStatus == PrefabInstanceStatus.Disconnected) {
                    QColorUtils.setColor(inactiveColor);
                    GUI.DrawTexture(rect, prefabTexture);
                    QColorUtils.clearColor();
                } else if (!showPrefabConnectedIcon && prefabStatus != PrefabInstanceStatus.NotAPrefab) {
                    QColorUtils.setColor(activeColor);
                    GUI.DrawTexture(rect, prefabTexture);
                    QColorUtils.clearColor();
                }
            #else
                PrefabType prefabType = PrefabUtility.GetPrefabType(gameObject);
                if (prefabType == PrefabType.MissingPrefabInstance || 
                    prefabType == PrefabType.DisconnectedPrefabInstance ||
                    prefabType == PrefabType.DisconnectedModelPrefabInstance)
                {
                    QColorUtils.setColor(inactiveColor);
                    GUI.DrawTexture(rect, prefabTexture);
                    QColorUtils.clearColor();
                }
                else if (!showPrefabConnectedIcon && prefabType != PrefabType.None)
                {
                    QColorUtils.setColor(activeColor);
                    GUI.DrawTexture(rect, prefabTexture);
                    QColorUtils.clearColor();
                }
            #endif
        }
    }
}