少年修仙传客户端基础资源
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using vnxbqy.UI;
using UnityEngine.UI;
 
[CustomEditor(typeof(TextUpdate))]
public class LabelTextColorTool : Editor
{
    [SerializeField] TextUpdate m_Target;
 
    [SerializeField] List<Text> allTexts = new List<Text>();
 
    [SerializeField] GUIStyle m_LabelStyle;
 
    [SerializeField] bool m_ShowTextColor;
 
    [SerializeField] Color m_LabelColor=Color.black;
    [SerializeField] int m_LabelSize = 12;
    [SerializeField] Vector3 m_Offset = Vector3.zero;
    [SerializeField] bool m_HexColor = false;
    [SerializeField] Color32 m_UnShowColor = Color.white;
 
    void FindAllText()
    {
        allTexts.Clear();
        FindChildText(m_Target.transform, ref allTexts);
    }
 
    private void OnEnable()
    {
        m_LabelStyle = new GUIStyle();
        m_LabelStyle.fontSize = 12;
        m_LabelStyle.normal.textColor = Color.green;
    }
 
    void FindChildText(Transform _transform, ref List<Text> _allTexts)
    {
        if (_transform != null)
        {
            var text = _transform.GetComponent<Text>();
            if (text != null)
            {
                _allTexts.Add(text);
            }
 
            for (int i = 0; i < _transform.childCount; i++)
            {
                FindChildText(_transform.GetChild(i), ref _allTexts);
            }
 
        }
    }
 
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        m_Target = target as TextUpdate;
        GUILayout.Space(20);
        if (GUILayout.Button("显示字色"))
        {
            if (m_Target != null)
            {
                FindAllText();
            }
        }
        m_LabelColor = EditorGUILayout.ColorField("字色", m_LabelColor);
        m_UnShowColor = EditorGUILayout.ColorField("屏蔽字色", m_UnShowColor);
        m_LabelSize = EditorGUILayout.IntField("字体大小", m_LabelSize);
        m_Offset = EditorGUILayout.Vector3Field("偏移", m_Offset);
        m_HexColor = EditorGUILayout.Toggle("16进制", m_HexColor);
    }
 
    private void OnSceneGUI()
    {
        for (int i = 0; i < allTexts.Count; i++)
        {
            if (allTexts[i] == null)
            {
                allTexts.RemoveAt(i);
                i--;
                continue;
            }
            var _pos = allTexts[i].rectTransform.position;
            Color32 m_Color = allTexts[i].color;
            if (m_UnShowColor.Equals(m_Color))
            {
                continue;
            }
            if (m_ShowTextColor)
            {
                allTexts[i].gameObject.SetActive(false);
            }
            else
            {
                allTexts[i].gameObject.SetActive(true);
            }
            m_LabelStyle.normal.textColor = m_LabelColor;
            m_LabelStyle.fontSize = m_LabelSize;
            _pos += m_Offset;
            Handles.Label(_pos,m_HexColor? GetHexColor(m_Color): m_Color.ToString(), m_LabelStyle);
            HandleUtility.Repaint();
        }
    }
 
    public string GetHexColor(Color32 _color)
    {
        return StringUtility.Contact(_color.r.ToString("X2"),
            _color.g.ToString("X2"),
            _color.b.ToString("X2"),
            _color.a.ToString("X2"));
    }
}