三国卡牌客户端基础资源仓库
lcy
2026-04-28 bcb2550e54cbbefcfdaa55bc74d2e2b24cfe4d8f
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
using System.Collections.Generic;
using System.IO;
using LitJson;
using UnityEngine;
 
/// <summary>
/// 编辑器语言配置读取助手
/// 负责统一解析 InitialFunction.txt
/// </summary>
public static class TextLanguageAdapterHelper
{
    public static string[] PresetLanguageIds { get; private set; }
    public static string[] PresetLanguageNames { get; private set; }
    private static bool s_Initialized;
 
    public static void Initialize()
    {
        if (s_Initialized) return;
 
        var idList = new List<string> { TextLanguageAdapter.DefaultLangId };
        var nameList = new List<string> { "默认" };
 
        string configPath = Path.Combine(Application.dataPath, "ResourcesOut/Config/InitialFunction.txt");
        if (File.Exists(configPath))
        {
            try
            {
                string[] lines = File.ReadAllLines(configPath);
                for (int i = 3; i < lines.Length; i++)
                {
                    string line = lines[i];
                    if (string.IsNullOrWhiteSpace(line)) continue;
                    
                    int index = line.IndexOf('\t');
                    if (index == -1) continue;
 
                    string key = line.Substring(0, index);
                    if (key == "LanguageEx")
                    {
                        string[] fields = line.Split('\t');
                        if (fields.Length > 1 && !string.IsNullOrEmpty(fields[1]))
                        {
                            var dict = JsonMapper.ToObject<Dictionary<string, string>>(fields[1]);
                            if (dict != null)
                            {
                                foreach (var kvp in dict)
                                {
                                    idList.Add(kvp.Key);
                                    nameList.Add(kvp.Value);
                                }
                            }
                        }
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogWarning($"[EditorLanguageHelper] 读取配置失败: {ex.Message}");
            }
        }
 
        PresetLanguageIds = idList.ToArray();
        PresetLanguageNames = nameList.ToArray();
        s_Initialized = true;
    }
}