using System.Collections.Generic; 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 = 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(fontLocation + config.relativePath).Asset as Font; // FontManager.RegisterFont(font); // } // else if (config.type == "2") // { // TMP_FontAsset fontAsset = // Assets.LoadAsset(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 keys = new Dictionary(); // 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; } } }