using System; using cfg.StringCfg; using Cysharp.Threading.Tasks; using Framework; using PhxhSDK; using SimpleJSON; using UnityEditor; using UnityEngine; using static StringManager; namespace Gameplay { class LoadingUILocalize : Singlenton { public StringConfig Config => cfg; StringConfig cfg; private async UniTask LoadByteBuf() { // todo: load from asset loader try { var filePath = string.Format("Assets/Config/UISomeAbout/LoadingUI/stringconfigUILoading.json"); //var loadAsset = AssetDatabase.LoadAssetAtPath(filePath); var loadAsset = await AssetManager.Instance.LoadAssetAsync(filePath); var jsonText = loadAsset.text; return JSON.Parse(jsonText); } catch (Exception e) { DebugUtil.LogError(e); } return null; } private async void LoadCfg() { try { var jsonNode = await LoadByteBuf(); if (jsonNode != null) { cfg = new cfg.StringCfg.StringConfig(jsonNode); } else { DebugUtil.LogError("LoadCfg Error, json node is null"); } } catch (Exception e) { DebugUtil.LogError(e); } } public void Init() { LoadCfg(); } private DataString GetByKey(string key) { var dataString = cfg.GetOrDefault(key); if (dataString == null || string.IsNullOrEmpty(dataString.Value)) { DebugUtil.LogError("{0}.GetStringConfigByKey: key = {1} is not exist, check table please!!", GetType(), key); } return dataString; } public string GetTextByIndex(int index) { if (cfg == null || index < 0 || index >= cfg.DataList.Count) { DebugUtil.LogError("--------------{0},-------{1}",cfg, index); return "error/error"; } DataString data = cfg.DataList[index]; string value = ""; if (data != null) { switch (StringManager.CurLanguage) { case (LanguageType.Default): { value = data.Value; break; } case (LanguageType.CN): { value = data.Value; break; } case (LanguageType.TW): { break; } case (LanguageType.EN): { value = data.ValueEn; break; } default: { DebugUtil.LogError($"==== 文本翻译的语言不存在相应的枚举值!请检查语言设置!!! ===="); break; } } } return value; } } }