123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using BeinLab.Util;
- using PublicTools.XMLDataBase;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- namespace XRTool.Util
- {
- /// <summary>
- /// 语言包的配置
- /// </summary>
- public class LanguagePackConf
- {
- private string language = "简体中文";
- private string packagePath;
- /// 语言包的名称
- /// </summary>
- public string Language { get => language; set => language = value; }
- /// <summary>
- /// 语言包的路径
- /// </summary>
- public string PackagePath { get => packagePath; set => packagePath = value; }
- public Dictionary<string, LanguageConf> LanguageMap { get => languageMap; set => languageMap = value; }
- private int min, max;
- public int GetMax()
- {
- return max;
- }
- public int GetMin()
- {
- return min;
- }
- /// <summary>
- /// 语言文本映射
- /// </summary>
- private Dictionary<string, LanguageConf> languageMap;
- public void ReadLanguageMap()
- {
- if (LanguageMap == null)
- {
- LanguageMap = new Dictionary<string, LanguageConf>();
- 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<LanguageConf>());
- #else
- string fullPath = Path.Combine(path, tableName + ".xml");
- GameNode.Instance.StartCoroutine(XSql.Instance.ReadServerData(fullPath, (List<LanguageConf> packList) =>
- {
- InitLanguage(packList);
- }));
- #endif
- }
- }
- public void InitLanguage(List<LanguageConf> 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]);
- }
- }
- }
- }
- /// <summary>
- /// 获取对应的语言文本的配置
- ///
- /// </summary>
- /// <param name="prikey"></param>
- 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;
- }
- }
- }
|