using BeinLab.Util; using PublicTools.XMLDataBase; using System.Collections.Generic; using System.Diagnostics; using System.IO; namespace XRTool.Util { /// /// 语言包的配置 /// public class LanguagePackConf { private string language = "简体中文"; private string packagePath; /// 语言包的名称 /// public string Language { get => language; set => language = value; } /// /// 语言包的路径 /// public string PackagePath { get => packagePath; set => packagePath = value; } public Dictionary LanguageMap { get => languageMap; set => languageMap = value; } private int min, max; public int GetMax() { return max; } public int GetMin() { return min; } /// /// 语言文本映射 /// private Dictionary languageMap; public void ReadLanguageMap() { if (LanguageMap == null) { LanguageMap = new Dictionary(); string tableName = typeof(LanguageConf).Name; string path = Path.Combine(ResourcesManager.LocalPath, BuildConfig.Instance.languagePath, packagePath); #if UNITY_EDITOR || !UNITY_ANDROID XSql.Instance.CloseTable(tableName); var table = XSql.Instance.OpenTable(path, tableName, ".xml", true); table.Open(); InitLanguage(table.FindAllData()); #else string fullPath = Path.Combine(path, tableName + ".xml"); GameNode.Instance.StartCoroutine(XSql.Instance.ReadServerData(fullPath, (List packList) => { InitLanguage(packList); })); #endif } } public void InitLanguage(List list) { if (list != null) { for (int i = 0; i < list.Count; i++) { if (!LanguageMap.ContainsKey(list[i].PriKey)) { if (i == 0) { string id= list[i].PriKey; id= id.Replace(BuildConfig.Instance.prefix,""); int.TryParse(id,out min); } else if (i == list.Count - 1) { string id = list[i].PriKey; id = id.Replace(BuildConfig.Instance.prefix, ""); int.TryParse(id, out max); } LanguageMap.Add(list[i].PriKey, list[i]); } } } } /// /// 获取对应的语言文本的配置 /// /// /// public LanguageConf GetLanguage(string prikey) { if (!string.IsNullOrEmpty(prikey)) { prikey = prikey.Trim(); if (!prikey.StartsWith(BuildConfig.Instance.prefix)) { prikey = BuildConfig.Instance.prefix + prikey; } if (LanguageMap != null && LanguageMap.ContainsKey(prikey)) { return LanguageMap[prikey]; } } return null; } } }