少年修仙传客户端基础资源
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
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text;
using System;
using System.Text.RegularExpressions;
 
 
public class ExcelParseTool : EditorWindow
{
    [SerializeField] string filePath = string.Empty;
    [SerializeField] string replaceFilePath = string.Empty;
    [SerializeField] string cacheDirectory = string.Empty;
    protected string[] lineStep = new string[] { "\r\n" }; //行间隔体
    public string[] m_Lines = null;
    FileInfo m_FileInfo;
    StringBuilder m_StringBuilder = new StringBuilder();
    List<int> m_FitterCols = new List<int>();
    List<string> m_FitterKeys = new List<string>();
    public Dictionary<string, string> m_Englishs = new Dictionary<string, string>();
    public Dictionary<string, string> m_EnglishReplaces = new Dictionary<string, string>();
    public Dictionary<FileInfo, string> m_AllTexts = new Dictionary<FileInfo, string>();
    [MenuItem("策划工具/Excel解析")]
    public static void OpenWindow()
    {
        ExcelParseTool _window = GetWindow(typeof(ExcelParseTool), false, "Excel解析") as ExcelParseTool;
        _window.Show();
        _window.autoRepaintOnSceneChange = true;
    }
 
    private void OnGUI()
    {
        GUI.skin.button.normal.textColor = Color.white;
        GUILayout.BeginHorizontal();
        GUILayout.Label(StringUtility.Contact("文件路径:", filePath));
        if (GUILayout.Button("Browser"))
        {
            filePath = EditorUtility.OpenFolderPanel("文件路径", "", "");
        }
 
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
 
        GUILayout.Label(StringUtility.Contact("替换文件:", replaceFilePath));
        if (GUILayout.Button("Browser"))
        {
            replaceFilePath = EditorUtility.OpenFilePanel("替换文件", "", "");
        }
 
        if (GUILayout.Button("解析"))
        {
            m_Englishs.Clear();
            ConfigInitiator.EditorLoad();
            m_FitterKeys.Clear();
            m_FitterKeys.AddRange(LanguageConfig.GetKeys());
            m_FitterKeys.AddRange(SysInfoConfig.GetKeys());
            m_FitterKeys.AddRange(IconConfig.GetKeys());
            FindEnglishLabel();
        }
 
        if (GUILayout.Button("替换"))
        {
            m_AllTexts.Clear();
            try
            {
                var _fileInfo = new FileInfo(replaceFilePath);
                var fs = _fileInfo.OpenRead();
                var sr = new StreamReader(fs, Encoding.UTF8);
                var lines = sr.ReadToEnd().Split(lineStep, StringSplitOptions.None);
                m_EnglishReplaces.Clear();
                for (int i = 0; i < lines.Length; i++)
                {
                    var _line = lines[i].Split('\t');
                    if (_line.Length > 1 && _line[1] != string.Empty)
                    {
                        m_EnglishReplaces.Add(_line[0], _line[1]);
                    }
                }
                fs.Dispose();
                fs.Close();
            }
            catch (Exception e)
            {
                DebugEx.LogError(e.ToString());
            }
            ConfigInitiator.EditorLoad();
            m_FitterKeys.Clear();
            m_FitterKeys.AddRange(LanguageConfig.GetKeys());
            m_FitterKeys.AddRange(SysInfoConfig.GetKeys());
            m_FitterKeys.AddRange(IconConfig.GetKeys());
            FindEnglishLabel(true);
        }
    }
 
    void FindEnglishLabel(bool _replace = false)
    {
        string[] _files = Directory.GetFiles(filePath, "*.txt", SearchOption.AllDirectories);
        if (_files == null || _files.Length == 0)
        {
            return;
        }
        var _index = 0;
        EditorApplication.update += delegate ()
        {
            var _fileInfo = new FileInfo(_files[_index]);
            m_FileInfo = _fileInfo;
            if (_fileInfo != null && (_fileInfo.Name == "Face.txt"
               || _fileInfo.Name == "ActorShow.txt"
               || _fileInfo.Name == "DirtyWord.txt"
               || _fileInfo.Name == "Audio.txt"
               || _fileInfo.Name == "Effect.txt"
               || _fileInfo.Name == "GmCmd.txt"
               || _fileInfo.Name == "Map.txt"
               || _fileInfo.Name == "Icon.txt"
               || _fileInfo.Name == "mapnpc.txt"
               || _fileInfo.Name == "Market.txt"
               || _fileInfo.Name == "PlayerProperty.txt"
               || _fileInfo.Name == "RichTextMsgReplace.txt"
               || _fileInfo.Name == "TablePath.txt"
               || _fileInfo.Name == "LoginSeverList.txt"
               || _fileInfo.Name == "FuncConfig.txt"
               || _fileInfo.Name == "logger.txt"))
            {
 
            }
            else
            {
                m_AllTexts.Add(m_FileInfo, string.Empty);
                try
                {
                    var fs = m_FileInfo.OpenRead();
                    var sr = new StreamReader(fs, Encoding.UTF8);
 
                    var lines = sr.ReadToEnd().Split(lineStep, StringSplitOptions.None);
                    ParseExcel(lines, true);
                    fs.Dispose();
                    fs.Close();
                }
                catch (Exception e)
                {
                    DebugEx.LogError(e.ToString());
                }
            }
 
            bool isCancel = EditorUtility.DisplayCancelableProgressBar("查找英文",
                         StringUtility.Contact(_index, "/", _files.Length), (float)_index / _files.Length);
            _index++;
            if (isCancel || _index >= _files.Length)
            {
                EditorApplication.update = null;
                EditorUtility.ClearProgressBar();
                _index = 0;
                if (_replace)
                {
                    foreach (var _key in m_AllTexts.Keys)
                    {
                        var _replaceInfo = new FileInfo(replaceFilePath);
                        using (FileStream _fs = new FileStream(StringUtility.Contact(_replaceInfo.DirectoryName, "/", _key.Name), FileMode.Create, FileAccess.Write, FileShare.Write))
                        {
                            using (StreamWriter sw = new StreamWriter(_fs, Encoding.UTF8))
                            {
                                sw.Write(m_AllTexts[_key]);
                            }
                        }
                    }
                    return;
                }
                using (FileStream fs = new FileStream(StringUtility.Contact(filePath, "/PathCache/logger.txt"), FileMode.Create, FileAccess.Write, FileShare.Write))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        foreach (var item in m_Englishs.Values)
                        {
                            sw.WriteLine(item);
                        }
                    }
                }
            }
        };
    }
 
    void ParseExcel(string[] lines, bool _replace = false)
    {
        m_FitterCols.Clear();
        var _types = lines[0].Split('\t');
        var _keys = lines[1].Split('\t');
        m_FitterCols.Add(0);
        m_Lines = lines;
        for (int i = 0; i < _types.Length; i++)
        {
            if (m_FileInfo.Name == "NPC.txt" && _types[i] == "int[]")
            {
                m_FitterCols.Add(i);
            }
            if (_types[i] == "int" || _types[i] == "int[]")
            {
                m_FitterCols.Add(i);
            }
        }
        for (int i = 0; i < _keys.Length; i++)
        {
            if (m_FileInfo.Name == "NPC.txt" && _keys[i] == "MODE")
            {
                m_FitterCols.Add(i);
            }
        }
        for (int i = 0; i < lines.Length; i++)
        {
            if (i < 3)
            {
                if (_replace)
                {
                    m_AllTexts[m_FileInfo] += lines[i];
                    m_AllTexts[m_FileInfo] += "\r\n";
                }
                continue;
            }
            FindEnglish(lines[i], _replace);
            EditorUtility.DisplayCancelableProgressBar("",
                      StringUtility.Contact(i, "/", lines.Length), (float)i / lines.Length);
        }
        if (_replace)
        {
            m_AllTexts[m_FileInfo] = m_AllTexts[m_FileInfo].Remove(m_AllTexts[m_FileInfo].Length - 2, 2);
        }
    }
 
    void FindEnglish(string line, bool _replace = false)
    {
        m_StringBuilder.Length = 0;
        var elements = line.Split('\t');
        for (int i = 0; i < elements.Length; i++)
        {
            if (m_FitterCols.Contains(i))
            {
                m_StringBuilder.Append(elements[i]);
                m_StringBuilder.Append('\t');
                continue;
            }
            var _label = elements[i];
            if (m_FitterKeys.Contains(_label.Trim()))
            {
                m_StringBuilder.Append(_label);
                m_StringBuilder.Append('\t');
                continue;
            }
            var _check = Regex.Replace(_label, "</r>", string.Empty);
            _check = Regex.Replace(_check, "<color=#[a-zA-Z0-9]+>", string.Empty);
            _check = Regex.Replace(_check, "</color>", string.Empty);
            _check = Regex.Replace(_check, "<size=[0-9]+>", string.Empty);
            _check = Regex.Replace(_check, "</size>", string.Empty);
            _check = Regex.Replace(_check, "<Word (.*?)/>", string.Empty);
            _check = Regex.Replace(_check, "<Img (.*?)/>", string.Empty);
            _check = Regex.Replace(_check, "<a>(.*?)</a>", string.Empty);
            _check = Regex.Replace(_check, "<Space=([0-9]*)>", string.Empty);
            _check = Regex.Replace(_check, "%s[0-9]+", string.Empty);
            MatchCollection _collection = Regex.Matches(_check, "[^a-zA-Z]*([a-zA-Z]+)[^a-zA-Z]*");
            if (_collection.Count > 0)
            {
                List<Match> _list = new List<Match>();
                for (int q = 0; q < _collection.Count; q++)
                {
                    _list.Add(_collection[q] as Match);
                }
                _list.Sort(Compare);
                for (int q = 0; q < _list.Count; q++)
                {
                    Match _match = _list[q];
                    if (m_FitterKeys.Contains(_match.Groups[1].Value))
                    {
                        continue;
                    }
                    if (_replace)
                    {
                        if (m_EnglishReplaces.ContainsKey(_match.Groups[1].Value))
                        {
                            _label = Regex.Replace(_label, _match.Groups[1].Value, m_EnglishReplaces[_match.Groups[1].Value]);
                        }
                    }
                    else if (!m_Englishs.ContainsKey(_match.Groups[1].Value))
                    {
                        m_Englishs.Add(_match.Groups[1].Value,
                            StringUtility.Contact(m_FileInfo.Name, "\t", "id:\t",
                           elements[0], "\t key:\t", m_Lines[1].Split('\t')[i].ToString(),
                            "\t", _match.Groups[1].Value));
                    }
                }
                m_StringBuilder.Append(_label);
                m_StringBuilder.Append('\t');
            }
            else
            {
                m_StringBuilder.Append(_label);
                m_StringBuilder.Append('\t');
            }
        }
        m_StringBuilder.Remove(m_StringBuilder.Length - 1, 1);
        m_AllTexts[m_FileInfo] += m_StringBuilder.ToString();
        m_AllTexts[m_FileInfo] += "\r\n";
    }
 
    int Compare(Match x, Match y)
    {
        return -x.Groups[1].Value.Length.CompareTo(y.Groups[1].Value.Length);
    }
}