NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/Login/LoadingUILocalize.cs

118 lines
3.5 KiB
C#

using cfg.StringCfg;
using Cysharp.Threading.Tasks;
using PhxhSDK;
using SimpleJSON;
using System;
using UnityEngine;
using static StringManager;
namespace Gameplay
{
class LoadingUILocalize : Singlenton<LoadingUILocalize>
{
public StringConfig Config => cfg;
StringConfig cfg;
private async UniTask<JSONNode> LoadByteBuf()
{
// todo: load from asset loader
try
{
var filePath = string.Format("Assets/Config/UISomeAbout/LoadingUI/stringconfigUILoading.json");
//var loadAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(filePath);
var loadAsset = await AssetManager.Instance.LoadAssetAsync<TextAsset>(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 (LanguageManager.CurLanguage)
{
case (LanguageManager.LanguageType.Default):
{
value = data.Value;
break;
}
case (LanguageManager.LanguageType.CN):
{
value = data.Value;
break;
}
case (LanguageManager.LanguageType.TW):
{
break;
}
case (LanguageManager.LanguageType.EN):
{
value = data.ValueEn;
break;
}
default:
{
DebugUtil.LogError($"==== 文本翻译的语言不存在相应的枚举值!请检查语言设置!!! ====");
break;
}
}
}
return value;
}
}
}