少年修仙传客户端基础资源
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;
using UnityEditor;
using UnityEngine;
 
public class TableTool : EditorWindow
{
 
    public static string configOutPutPath;
    static bool isIL = false; // 导出表代码是否IL使用
 
    [UnityEditor.MenuItem("策划工具/导出策划表到游戏工程")]
    static void Init()
    {
        configOutPutPath = UnityEngine.Application.dataPath + "/StreamingAssets/Config";
        window = GetWindow(typeof(TableTool), false, "策划导表工具") as TableTool;
        window.position = new Rect(UnityEngine.Screen.width / 2, UnityEngine.Screen.height / 2, 300, 700);
        window.Show();
        //PathCache();
    }
 
    public class FileToggleInfo
    {
        public FileToggleInfo(FileInfo file, bool sel)
        {
            fileInfo = file;
            isSelect = sel;
        }
 
        public FileInfo fileInfo = null;
        public bool isSelect = false;
    }
 
    private static TableTool window = null;
    private Vector2 scrollPosition;
    private static string _tablePath = "";
    private static List<FileToggleInfo> _tableNameLst = new List<FileToggleInfo>(); //所有表名字列表
    private void OnGUI()
    {
        _tablePath = UnityEngine.Application.dataPath + "/ResourcesOut/Refdata/Config";
        GUILayout.BeginVertical();
        GUILayout.TextArea("策划配表路径:" + _tablePath);
 
        GUILayout.Box(new GUIContent("路径下的所有表:"));
 
        scrollPosition = GUILayout.BeginScrollView(scrollPosition);
        ShowTableNames();
        GUILayout.EndScrollView();
 
        GUILayout.FlexibleSpace();
 
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("刷新"))
        {
            GetDicFiles();
        }
        if (GUILayout.Button("全选"))
        {
            SelectAll();
        }
        GUILayout.EndHorizontal();
 
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("导出表"))
        {
            isIL = false;
            ReadAllTxt();
            GenAllClass();
            MessageBox.Show("导出表成功!");
            AssetDatabase.Refresh();
        }
        GUILayout.EndHorizontal();
 
        //        GUILayout.BeginHorizontal();
        //        if (GUILayout.Button("导出IL表"))
        //        {
        //            isIL = true;
        //            ReadAllTxt();
        //            GenAllClass();
        //            MessageBox.Show("导出IL表成功!");
        //            AssetDatabase.Refresh();
        //            isIL = false;
        //        }
        //        GUILayout.EndHorizontal();
 
 
        //        if (GUILayout.Button("选择路径"))
        //        {
        //#if UNITY_EDITOR
        //            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
 
        //            if (folderBrowserDialog.ShowDialog() == DialogResult.OK || folderBrowserDialog.ShowDialog() == DialogResult.Yes)
        //            {
        //                _tablePath = folderBrowserDialog.SelectedPath + "\\";
        //                PathCache(_tablePath);
        //            }
 
        //            folderBrowserDialog.Dispose();
        //#endif
 
        //        }
        GUIUtility.ExitGUI();
    }
 
    private void ShowTableNames()
    {
        if (_tableNameLst == null)
        {
            return;
        }
        for (int i = 0; i < _tableNameLst.Count; i++)
        {
            string tableName = _tableNameLst[i].fileInfo.Name;
 
            _tableNameLst[i].isSelect = GUILayout.Toggle(_tableNameLst[i].isSelect, tableName);
 
        }
    }
 
    private void GetDicFiles()
    {
        if (string.IsNullOrEmpty(_tablePath))
        {
            MessageBox.Show("请选择策划表路径!");
            return;
        }
        _tableNameLst.Clear();
        DirectoryInfo folder = new DirectoryInfo(@_tablePath);
        if (folder != null)
        {
            FileInfo[] fileInfoArr = folder.GetFiles("*.txt");
            if (fileInfoArr == null || fileInfoArr.Length <= 0)
            {
                return;
            }
            for (int i = 0, length = fileInfoArr.Length; i < length; i++)
            {
                _tableNameLst.Add(new FileToggleInfo(fileInfoArr[i], false));
            }
        }
    }
 
    /// <summary>
    /// 选中所有表
    /// </summary>
    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;
        }
    }
 
    [UnityEditor.MenuItem("Assets/生成配置解析类型")]
    public static void GenerateConfigClass()
    {
        _tableNameLst.Clear();
 
        if (UnityEditor.Selection.objects != null)
        {
            foreach (var o in UnityEditor.Selection.objects)
            {
                var objectName = AssetDatabase.GetAssetPath(o.GetInstanceID());
                if (objectName.EndsWith(".txt") || objectName.EndsWith(".TXT"))
                {
                    _tableNameLst.Add(new FileToggleInfo(new FileInfo(objectName), true));
                }
            }
 
            GenAllClass();
            AssetDatabase.Refresh();
        }
 
        _tableNameLst.Clear();
 
        MessageBox.Show("导出成功!");
    }
 
    public static void CopyConfigsToOutPutPath(string _outPath)
    {
        configOutPutPath = _outPath;
        var root1 = UnityEngine.Application.dataPath + "/ResourcesOut/Refdata/Config";
        var configFiles = new List<FileInfo>();
        configFiles.AddRange(FileExtersion.GetFileInfos(root1, new string[] { "*.txt", "*.TXT" }));
        var root2 = UnityEngine.Application.dataPath + "/Resources/Config";
        if (Directory.Exists(root2))
        {
            var fileInfos = FileExtersion.GetFileInfos(root2, new string[] { "*.txt", "*.TXT" });
            if (fileInfos != null)
            {
                configFiles.AddRange(fileInfos);
            }
        }
 
        foreach (var file in configFiles)
        {
            var fileInfo = new FileInfo(file.FullName);
            CopyTxt(fileInfo);
        }
    }
 
    /// <summary>
    /// 导出所有表
    /// </summary>
    private void ReadAllTxt()
    {
        if (string.IsNullOrEmpty(_tablePath))
        {
            MessageBox.Show("请选择策划表路径!");
            return;
        }
        if (_tableNameLst == null)
        {
            MessageBox.Show("当前路径下没有可读取的策划表!");
            return;
        }
        for (int i = 0; i < _tableNameLst.Count; i++)
        {
            if (!_tableNameLst[i].isSelect)
            {
                continue;
            }
            CopyTxt(_tableNameLst[i].fileInfo);
        }
    }
 
    private static void CopyTxt(FileInfo fileInfo)
    {
        string fileName = fileInfo.Name.Split('.')[0];
 
        if (!Directory.Exists(configOutPutPath))
        {
            Directory.CreateDirectory(configOutPutPath);
        }
 
        string filePath = configOutPutPath + "/" + fileName + ".txt";
        if (File.Exists(filePath))
        {
            File.Delete(filePath);
        }
 
        File.Copy(fileInfo.FullName, filePath);
    }
 
    /// <summary>
    /// 生成所有表模型
    /// </summary>
    private static void GenAllClass()
    {
        if (_tableNameLst == null)
        {
            return;
        }
 
        for (int i = 0; i < _tableNameLst.Count; i++)
        {
            if (!_tableNameLst[i].isSelect)
            {
                continue;
            }
            FileStream fileStream = _tableNameLst[i].fileInfo.OpenRead();
            StreamReader sr = new StreamReader(fileStream, Encoding.UTF8);
            CreateConfigClassFile.CreateConfigClass(_tableNameLst[i].fileInfo, isIL);
            sr.Dispose();
            sr.Close();
        }
    }
 
    /// <summary>
    /// 路径缓存
    /// </summary>
    /// <param name="setPath"></param>
    //private static void PathCache(string setPath = "")
    //{
    //    DebugEx.Log("路径缓存:" + setPath);
    //    string configPath = UnityEngine.Application.dataPath;
    //    configPath = configPath + "/ResourcesOut/Refdata/Config/PathCache/TablePath.txt";
    //    FileStream configPathTxt = File.Open(configPath, FileMode.Open);
    //    if (string.IsNullOrEmpty(setPath))
    //    {
    //        StreamReader sr = new StreamReader(configPathTxt);
    //        string path = sr.ReadToEnd();
    //        _tablePath = path;
    //        sr.Dispose();
    //        sr.Close();
    //    }
    //    else
    //    {
    //        StreamWriter sw = new StreamWriter(configPathTxt);
    //        sw.Write(setPath);
    //        sw.Dispose();
    //        sw.Close();
    //    }
    //}
}
 
public class Param
{
    public int Paramindex;
    public string AttType;
    public Type SysType;
    public List<string> ParmValue = null;
    public string SampleValue;
    public string parmName;
    public string SrcParmName;
    public string parmComment;
 
    public Param(string attType, string attName, string attcomment, string samValue, int index)
    {
        ParmValue = new List<string>();
        Paramindex = index;
        SetParmName(attName);
        parmComment = attcomment;
        SampleValue = samValue;
 
        StringBuilder valueSb = new StringBuilder();
        valueSb.Append("modelDetails[");
        valueSb.Append(index.ToString());
        valueSb.Append("].Trim()");
        string value = valueSb.ToString();
        attType = attType.Trim();
 
        switch (attType)
        {
            case "int":
                {
                    SysType = typeof(System.Int32);
                    SetSigleValue("int", value);
                }
                break;
            case "Int64":
                {
                    SysType = typeof(System.Int64);
                    SetSigleValue("Int64", value);
                }
                break;
            case "string":
                {
                    SysType = typeof(System.String);
                    ParmValue.Add(value + ";");
                }
                break;
 
            case "bool":
                {
                    SysType = typeof(System.Boolean);
                    ParmValue.Add(value + ";");
                }
                break;
            case "float":
                {
                    SysType = typeof(System.Double);
                    SetSigleValue("float", value);
                }
                break;
            case "byte":
                {
                    SysType = typeof(System.Byte);
                    SetSigleValue("byte", value);
                }
                break;
            case "double":
                {
                    SysType = typeof(System.Double);
                    SetSigleValue("double", value);
                }
                break;
            case "int[]":
                SysType = Type.GetType("System.Int32[]");
                SetValue("int", value, SampleValue);
                break;
            case "string[]":
                SysType = Type.GetType("System.String[]");
                SetValue("string", value, SampleValue);
                break;
            case "double[]":
                SysType = Type.GetType("System.Double[]");
                SetValue("double", value, SampleValue);
                break;
            default: SysType = null; break;
        }
    }
 
    private void SetValue(string paramType, string value, string sampleValue)
    {
        string[] valueSpArray = sampleValue.Split('|');
        if (valueSpArray == null)
        {
            return;
        }
 
        StringBuilder arrayName = new StringBuilder();
        arrayName.Append(parmName);
        arrayName.Append("SplitArray");
 
        StringBuilder firstValue = new StringBuilder();
        firstValue.Append("string[] ");
        firstValue.Append(arrayName.ToString());
        firstValue.Append(" = ");
        firstValue.Append(value);
        firstValue.Append(".Split('|');");
        ParmValue.Add(firstValue.ToString());
 
        StringBuilder secondValue = new StringBuilder();
        secondValue.Append(parmName);
        secondValue.Append(" = new ");
        secondValue.Append(paramType);
        secondValue.Append("[" + valueSpArray.Length + "];");
        ParmValue.Add(secondValue.ToString());
 
        ParmValue.Add(string.Format("for (int i = 0; i < {0}.Length; i++) {", parmName));
        ParmValue.Add(string.Format("   {0}[i] = IsNumeric({1}SplitArray[i]) ? double.Parse({2}SplitArray[i]) : (double)0;", parmName, parmName, parmName));
        ParmValue.Add("}");
    }
 
    private void SetSigleValue(string paramType, string value)
    {
        StringBuilder strBld = new StringBuilder();
        strBld.Append("IsNumeric(");
        strBld.Append(value);
        strBld.Append(string.Format(")? {0}.Parse(", paramType));
        strBld.Append(value);
        strBld.Append(string.Format("):({0})0;", paramType));
        ParmValue.Add(strBld.ToString());
    }
 
    public void SetParmName(string fieldName)
    {
        string fName = fieldName.Replace(" ", "");
        fName = fName.Split('[')[0];
        SrcParmName = fName;
        fName = "_" + fName.ToLower();
        parmName = fName;
    }
 
}