79 lines
2.8 KiB
C#
79 lines
2.8 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace NBC
|
|
{
|
|
public class LanguageFont : ILanguage
|
|
{
|
|
/// <summary>
|
|
/// 多语言字体配置数据
|
|
/// </summary>
|
|
private readonly Dictionary<SystemLanguage, Dictionary<string, string>> _languages =
|
|
new Dictionary<SystemLanguage, Dictionary<string, string>>();
|
|
|
|
/// <summary>
|
|
/// 当前语言图片配置键值对
|
|
/// </summary>
|
|
private Dictionary<string, string> _currentLanguageDictionary = new Dictionary<string, string>();
|
|
|
|
public string Get(string key)
|
|
{
|
|
if (_currentLanguageDictionary != null && _currentLanguageDictionary.TryGetValue(key, out var value))
|
|
{
|
|
return value;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public void AddLanguage(SystemLanguage language)
|
|
{
|
|
// var configDic = GameConfig.Inst.GetLanguageFontConfig(LanguageConst.languageMap[language]);
|
|
// string fontLocation = "Assets/ResRaw/Fonts/";
|
|
// //字体使用前需要先注册
|
|
// foreach (var config in configDic.Values)
|
|
// {
|
|
// if (config.type == "1")
|
|
// {
|
|
// DynamicFont font = new DynamicFont();
|
|
// font.name = config.name;
|
|
// font.nativeFont = Assets.LoadAsset<Font>(fontLocation + config.relativePath).Asset as Font;
|
|
// FontManager.RegisterFont(font);
|
|
// }
|
|
// else if (config.type == "2")
|
|
// {
|
|
// TMP_FontAsset fontAsset =
|
|
// Assets.LoadAsset<TMP_FontAsset>(fontLocation + config.relativePath).Asset as TMP_FontAsset;
|
|
// TMPFont font = new TMPFont();
|
|
// font.name = config.name; //这个名字要和编辑器里字体资源的名字一致
|
|
// font.fontAsset = fontAsset;
|
|
// FontManager.RegisterFont(font);
|
|
// }
|
|
// }
|
|
//
|
|
// var font2KeyDic = GameConfig.Inst.GetFont2KeyDic();
|
|
// Dictionary<string, string> keys = new Dictionary<string, string>();
|
|
// foreach (var pair in font2KeyDic)
|
|
// {
|
|
// keys.Add(pair.Key, configDic[pair.Value].name);
|
|
// }
|
|
//
|
|
// if (keys != null)
|
|
// {
|
|
// _languages[language] = keys;
|
|
// }
|
|
}
|
|
|
|
public bool UseLanguage(SystemLanguage language)
|
|
{
|
|
if (_languages.TryGetValue(language, out var language1))
|
|
{
|
|
_currentLanguageDictionary = language1;
|
|
return true;
|
|
}
|
|
|
|
Debug.LogError("字体配置不存在");
|
|
return false;
|
|
}
|
|
}
|
|
} |