少年修仙传客户端基础资源
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using UnityEngine.UI;
using System.Windows.Forms;
using vnxbqy.UI;
 
 
//导出已打开的(或者指定名)界面用到的图片 
public class ExportPrefabsIMG : EditorWindow {
 
    private static string topFilePath= "Assets/ResourcesOut/UI/Window/";
    private static string builtInFilePath = "Assets/ResourcesOut/BuiltIn/Prefabs/";
    private static string priorityWindowFilePath = "Assets/ResourcesOut/UI/PriorityWindow/";
 
    private static ExportPrefabsIMG window = null;
    private Vector2 scrollPosition;
    private static int exportType = 0; //0 运行时界面 1 builtin目录界面 2 window目录界面 3 priorityWindow目录界面
 
 
    public class FileToggleInfo
    {
        public FileToggleInfo(string fileName, bool sel)
        {
            fileInfo = fileName;
            isSelect = sel;
        }
 
        public string fileInfo = null;
        public bool isSelect = false;
    }
 
    private static List<FileToggleInfo> _tableNameLst = new List<FileToggleInfo>(); //所有表名字列表
 
 
    [UnityEditor.MenuItem("策划工具/导出指定界面的图片", false)]
    static void Init()
    {
        exportType = 0;
        window = GetWindow(typeof(ExportPrefabsIMG), false, "导出界面图片,运行时导出会更准确") as ExportPrefabsIMG;
        window.position = new Rect(UnityEngine.Screen.width / 2, UnityEngine.Screen.height / 2, 300, 700);
        window.Show();
    }
 
    private void OnGUI()
    {
        GUILayout.BeginVertical();
 
        scrollPosition = GUILayout.BeginScrollView(scrollPosition);
        ShowTableNames();
        GUILayout.EndScrollView();
 
        GUILayout.FlexibleSpace();
 
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("刷新运行时界面"))
        {
            exportType = 0;
            GetDicFiles();
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("刷新builtIn界面"))
        {
            exportType = 1;
            GetDicFiles();
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("刷新Window界面"))
        {
            exportType = 2;
            GetDicFiles();
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("刷新PriorityWindow界面"))
        {
            exportType = 3;
            GetDicFiles();
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("全选"))
        {
            SelectAll();
        }
        GUILayout.EndHorizontal();
 
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("导出图片"))
        {
            Export();
            MessageBox.Show("导出图片成功!(查看根目录的OpenWindowImages)");
            AssetDatabase.Refresh();
        }
        GUILayout.EndHorizontal();
 
        
        GUIUtility.ExitGUI();
    }
 
    private void ShowTableNames()
    {
        if (_tableNameLst == null)
        {
            return;
        }
        for (int i = 0; i < _tableNameLst.Count; i++)
        {
            string tableName = _tableNameLst[i].fileInfo;
 
            _tableNameLst[i].isSelect = GUILayout.Toggle(_tableNameLst[i].isSelect, tableName);
 
        }
    }
 
    // 0 运行时界面 1 builtin目录界面 2 window目录界面
    private void GetDicFiles()
    {
        _tableNameLst.Clear();
        if (exportType == 0)
        {
            if (!EditorApplication.isPlaying || WindowCenter.Instance.openWinNames.IsNullOrEmpty())
            {
                MessageBox.Show("请在游戏运行时打开界面");
                return;
            }
 
            foreach (var item in WindowCenter.Instance.openWinNames)
            {
                _tableNameLst.Add(new FileToggleInfo(item.Key, false));
            }
        }
        else if (exportType == 1)
        {
            DirectoryInfo folder = new DirectoryInfo(@builtInFilePath);
            if (folder != null)
            {
                FileInfo[] fileInfoArr = folder.GetFiles("*.prefab");
                if (fileInfoArr == null || fileInfoArr.Length <= 0)
                {
                    return;
                }
                for (int i = 0, length = fileInfoArr.Length; i < length; i++)
                {
                    _tableNameLst.Add(new FileToggleInfo(fileInfoArr[i].Name.Split('.')[0], false));
                }
            }
        }
        else if (exportType == 2)
        {
            DirectoryInfo folder = new DirectoryInfo(@topFilePath);
            if (folder != null)
            {
                FileInfo[] fileInfoArr = folder.GetFiles("*.prefab");
                if (fileInfoArr == null || fileInfoArr.Length <= 0)
                {
                    return;
                }
                for (int i = 0, length = fileInfoArr.Length; i < length; i++)
                {
                    _tableNameLst.Add(new FileToggleInfo(fileInfoArr[i].Name.Split('.')[0], false));
                }
            }
        }
        else if (exportType == 3)
        {
            DirectoryInfo folder = new DirectoryInfo(@priorityWindowFilePath);
            if (folder != null)
            {
                FileInfo[] fileInfoArr = folder.GetFiles("*.prefab");
                if (fileInfoArr == null || fileInfoArr.Length <= 0)
                {
                    return;
                }
                for (int i = 0, length = fileInfoArr.Length; i < length; i++)
                {
                    _tableNameLst.Add(new FileToggleInfo(fileInfoArr[i].Name.Split('.')[0], false));
                }
            }
        }
 
    }
 
    private void SelectAll()
    {
        if (_tableNameLst == null)
        {
            MessageBox.Show("请先刷新界面");
            return;
        }
        for (int i = 0; i < _tableNameLst.Count; i++)
        {
            if (_tableNameLst[i] == null)
            {
                continue;
            }
            if (_tableNameLst[i].fileInfo == null)
            {
                continue;
            }
            _tableNameLst[i].isSelect = true;
        }
    }
 
    private void Export()
    {
        //导出指定界面 或者 选中已打开的界面
        if (!Directory.Exists("OpenWindowImages"))
            Directory.CreateDirectory("OpenWindowImages");
 
        if (_tableNameLst == null)
        {
            MessageBox.Show("先刷新界面");
            return;
        }
        for (int i = 0; i < _tableNameLst.Count; i++)
        {
            if (!_tableNameLst[i].isSelect)
            {
                continue;
            }
 
            string fileName = _tableNameLst[i].fileInfo;
            string filePath;
            if (exportType == 0)
            {
                if (WindowCenter.Instance.openWinNames[fileName])
                {
                    filePath = builtInFilePath + _tableNameLst[i].fileInfo + ".prefab";
                }
                else
                {
                    filePath = topFilePath + _tableNameLst[i].fileInfo + ".prefab";
                }
                if (!File.Exists(filePath))
                {
                    filePath = priorityWindowFilePath + _tableNameLst[i].fileInfo + ".prefab";
                }
            }
            else if (exportType == 1)
            {
                filePath = builtInFilePath + _tableNameLst[i].fileInfo + ".prefab";
            }
            else if (exportType == 2)
            { 
                filePath = topFilePath + _tableNameLst[i].fileInfo + ".prefab";
            }
            else
            {
                filePath = priorityWindowFilePath + _tableNameLst[i].fileInfo + ".prefab";
            }
 
            GameObject _prefab = AssetDatabase.LoadAssetAtPath<GameObject>(filePath);
            if (_prefab == null)
            {
                Debug.LogFormat("无法取得文件 {0}", filePath);
                continue;
            }
            Image[] transArr14 = _prefab.GetComponentsInChildren<Image>(true);
            foreach (Image item in transArr14)
            {
                var path = AssetDatabase.GetAssetPath(item.sprite.GetInstanceID());
                if (string.IsNullOrEmpty(path)) continue;
                if (!path.Contains("ResourcesOut")) continue;
                if (!Directory.Exists("OpenWindowImages/" + fileName))
                    Directory.CreateDirectory("OpenWindowImages/" + fileName);
 
                var arr = path.Replace("Sprite","@").Split("@");
                if (arr.Length == 2)
                {
                    var aa = arr[1].Split("/");
                    if (aa.Length != 1)
                    {
                        if (!Directory.Exists("OpenWindowImages/" + fileName + "/" + aa[1]))
                            Directory.CreateDirectory("OpenWindowImages/" + fileName + "/" + aa[1]);
                        if (!File.Exists("OpenWindowImages/" + fileName + "/" + aa[1] + "/" + item.sprite.name + ".png"))
                            File.Copy(path, "OpenWindowImages/" + fileName + "/" + aa[1] + "/" + item.sprite.name + ".png");
 
                        if (!File.Exists("OpenWindowImages/" + fileName + "/" + aa[1] + "/" + item.sprite.name + ".png.meta"))
                            File.Copy(path, "OpenWindowImages/" + fileName + "/" + aa[1] + "/" + item.sprite.name + ".png.meta");
                    }
                }
                
                //if (!File.Exists("OpenWindowImages/" + fileName + "/" + item.sprite.name + ".png"))
                //    File.Copy(path, "OpenWindowImages/" + fileName + "/" + item.sprite.name + ".png");
            }
        }
 
    
    }
 
  
}