using System.Collections.Generic;
using FairyGUI;
using TMPro;
using UnityEngine;
namespace NBC
{
public class LanguageFont : ILanguage
{
///
/// 多语言字体配置数据
///
private readonly Dictionary> _languages =
new Dictionary>();
///
/// 当前语言和字体
///
private Dictionary _currentLanguageDictionary = new Dictionary();
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 = Lan.Inst.GetLanguageFontConfig(LanguageConst.languageMap[language]);
// string fontLocation = "Fonts/";//"Assets/Resources/Fonts/";
//字体使用前需要先注册
foreach (var config in configDic.Values)
{
// if (config.Type == "1")
// {
// DynamicFont font = new DynamicFont();
// font.name = config.Name;
// font.nativeFont = Resources.Load(fontLocation + config.RelativePath);
// FontManager.RegisterFont(font);
// }
// else if (config.Type == "2")
// {
// TMP_FontAsset fontAsset =
// Resources.Load(fontLocation + config.RelativePath) as TMP_FontAsset;
// TMPFont font = new TMPFont();
// font.name = config.Name; //这个名字要和编辑器里字体资源的名字一致
// font.fontAsset = fontAsset;
// FontManager.RegisterFont(font);
// }
}
var font2KeyDic = Lan.Inst.GetFont2KeyDic();
Dictionary keys = new Dictionary();
foreach (var pair in font2KeyDic)
{
keys.Add(pair.Key, configDic[pair.Value].Name);
}
_languages[language] = keys;
}
public bool UseLanguage(SystemLanguage language)
{
if (_languages.TryGetValue(language, out var language1))
{
_currentLanguageDictionary = language1;
return true;
}
Debug.LogError("字体配置不存在");
return false;
}
}
}