using System.Collections.Generic;
using System.IO;
using LitJson;
using UnityEngine;
///
/// 编辑器语言配置读取助手
/// 负责统一解析 InitialFunction.txt
///
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 { TextLanguageAdapter.DefaultLangId };
var nameList = new List { "默认" };
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>(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;
}
}