少年修仙传客户端基础资源
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
174
175
176
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using UnityEngine.UI;
public static class ButtonAreaTool
{
    static public void OnGUI()
    {
        ToolsHelper.DisplayFolderPath();
 
        if (GUILayout.Button("查找"))
        {
            m_ButtonDict.Clear();
            m_ButtonPaths.Clear();
            m_SpreadDict.Clear();
            StartFindButton();
        }
 
        GUILayout.BeginHorizontal();
        GUILayout.Label(m_ExportPath);
        if (GUILayout.Button("导出路径"))
        {
            m_ExportPath = EditorUtility.OpenFolderPanel("导出路径", "", "");
        }
        if (m_ButtonDict.Count > 0 && GUILayout.Button("导出"))
        {
            Export();
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
 
        m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition);
        var _index = 0;
        foreach (var _prefab in m_ButtonDict.Keys)
        {
            GUILayout.BeginHorizontal();
            EditorGUILayout.ObjectField(_prefab, typeof(GameObject), false);
            if(GUILayout.Button(m_SpreadDict[_prefab]? "收起" : "展开"))
            {
                m_SpreadDict[_prefab] = !m_SpreadDict[_prefab];
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            if (!m_SpreadDict[_prefab])
            {
                continue;
            }
            var _list = m_ButtonDict[_prefab];
            for (int i = 0; i < _list.Count; i++)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Goto"))
                {
                    var _go = GameObject.Find(m_ButtonPaths[_index]);
                    if (_go != null)
                    {
                        Selection.activeGameObject = _go;
                    }
                }
                EditorGUILayout.Vector2Field("按钮区域",_list[i].buttonArea);
                if (!_list[i].Equals(default(Vector2)))
                {
                    EditorGUILayout.Vector2Field("检测区域", _list[i].rayArea);
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                _index++;
            }
            GUILayout.Space(10);
        }
        GUILayout.EndScrollView();
    }
 
    static Dictionary<GameObject, List<ButtonRayArea>> m_ButtonDict = new Dictionary<GameObject, List<ButtonRayArea>>();
    static Dictionary<GameObject, bool> m_SpreadDict = new Dictionary<GameObject, bool>();
    static List<string> m_ButtonPaths = new List<string>();
    static Vector2 m_ScrollPosition = Vector2.zero;
 
    static string m_ExportPath = string.Empty;
 
    static void StartFindButton()
    {
        var _files = Directory.GetFiles(ToolsHelper.folderPath, "*.prefab", SearchOption.AllDirectories);
        if (_files == null || _files.Length == 0)
        {
            return;
        }
        var _index = 0;
        EditorApplication.update = delegate ()
        {
            var _file = _files[_index];
            GameObject _prefab = AssetDatabase.LoadAssetAtPath(ToolsHelper.GetRelativeAssetsPath(_file), typeof(GameObject)) as GameObject;
            if (_prefab != null)
            {
                var _buttons = _prefab.GetComponentsInChildren<Button>(true);
                if (_buttons != null && _buttons.Length > 0)
                {
                    List<ButtonRayArea> _list = null;
                    if (!m_ButtonDict.TryGetValue(_prefab, out _list))
                    {
                        _list = new List<ButtonRayArea>();
                        m_ButtonDict.Add(_prefab, _list);
                        m_SpreadDict.Add(_prefab, false);
                    }
                    for (int i = 0, imax = _buttons.Length; i < imax; i++)
                    {
                        m_ButtonPaths.Add(GetParentName(_buttons[i].transform));
                        var _buttonSize = (_buttons[i].transform as RectTransform).sizeDelta;
                        var _ray = _buttons[i].transform.GetComponentInChildren<RayAccepter>(true);
                        var _raySize = default(Vector2);
                        if (_ray != null)
                        {
                            _raySize = (_ray.transform as RectTransform).sizeDelta;
                        }
                        _list.Add(new ButtonRayArea()
                        {
                            buttonArea = _buttonSize,
                            rayArea = _raySize,
                            hasRay = _ray != null,
                        });
                    }
                }
            }
            bool _isCancel = EditorUtility.DisplayCancelableProgressBar("查找按钮监听区域",
                StringUtility.Contact(_index, "/", _files.Length), (float)_index / _files.Length);
            _index++;
            if (_isCancel || _index >= _files.Length)
            {
                EditorUtility.ClearProgressBar();
                EditorApplication.update = null;
                _index = 0;
            }
        };
    }
 
    static string GetParentName(Transform _parent)
    {
        if (_parent.parent != null)
        {
            return StringUtility.Contact(GetParentName(_parent.parent), "/", _parent.name);
        }
        return _parent.name;
    }
 
    static void Export()
    {
        using (FileStream fs = new FileStream(StringUtility.Contact(m_ExportPath, "/logger.txt"), FileMode.Create, FileAccess.Write))
        {
            using (StreamWriter sw = new StreamWriter(fs))
            {
                var _index = 0;
                foreach (var _prefab in m_ButtonDict.Keys)
                {
                    var _list = m_ButtonDict[_prefab];
                    for (int i = 0; i < _list.Count; i++)
                    {
                        sw.WriteLine(StringUtility.Contact("预制体名称:", "\t", _prefab.name, "\t",
                            "按钮路径:", "\t", m_ButtonPaths[_index], "\t",
                            "按钮区域:", "\t", _list[i].buttonArea.ToString(), "\t",
                            _list[i].hasRay ? StringUtility.Contact("检测区域:\t", _list[i].rayArea.ToString()) : string.Empty));
                        _index++;
                    }
                }
            }
        }
    }
 
    struct ButtonRayArea
    {
        public Vector2 buttonArea;
        public Vector2 rayArea;
        public bool hasRay;
    }
}