首次提交
This commit is contained in:
3
Assets/Scripts/NBC/Language/Runtime.meta
Normal file
3
Assets/Scripts/NBC/Language/Runtime.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35f7b912a3794f2290a6d67d5b129707
|
||||
timeCreated: 1715247864
|
||||
3
Assets/Scripts/NBC/Language/Runtime/Const.meta
Normal file
3
Assets/Scripts/NBC/Language/Runtime/Const.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 890ea39b289a4325b3b23ad5e075f774
|
||||
timeCreated: 1715247915
|
||||
62
Assets/Scripts/NBC/Language/Runtime/Const/LanguageConst.cs
Normal file
62
Assets/Scripts/NBC/Language/Runtime/Const/LanguageConst.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public struct LanguageInfo
|
||||
{
|
||||
public SystemLanguage Language;
|
||||
public string Name;
|
||||
public string Code;
|
||||
}
|
||||
|
||||
public class LanguageConst
|
||||
{
|
||||
public const string LanguageSaveKey = "LanguageSaveKey";
|
||||
|
||||
//简体中文、繁体中文、英语、日语、韩语、泰语、越南语、法语、德语、葡萄牙与、西班牙语、俄语、波兰语、荷兰语、
|
||||
|
||||
|
||||
//简体中文、繁体中文、英语、日语、德语、俄语、法语、西班牙语、韩语、葡萄牙
|
||||
|
||||
//土耳其语、意大利语、印度尼西亚语,阿拉伯语,泰语、越南语、波兰语、荷兰语
|
||||
|
||||
public static readonly List<LanguageInfo> LanguageList = new List<LanguageInfo>()
|
||||
{
|
||||
new LanguageInfo() { Language = SystemLanguage.English, Name = "English", Code = "en" },
|
||||
new LanguageInfo() { Language = SystemLanguage.ChineseSimplified, Name = "简体中文", Code = "zh-CN" },
|
||||
new LanguageInfo() { Language = SystemLanguage.ChineseTraditional, Name = "繁體中文", Code = "zh-TW" },
|
||||
// new LanguageInfo() { Language = SystemLanguage.Japanese, Name = "日本語", Code = "ja" },
|
||||
// new LanguageInfo() { Language = SystemLanguage.French, Name = "Français", Code = "fr" },
|
||||
// new LanguageInfo() { Language = SystemLanguage.German, Name = "Deutsch", Code = "de" },
|
||||
// new LanguageInfo() { Language = SystemLanguage.Korean, Name = "한국어", Code = "ko" },
|
||||
// new LanguageInfo() { Language = SystemLanguage.Russian, Name = "Русский", Code = "ru" },
|
||||
// new LanguageInfo() { Language = SystemLanguage.Spanish, Name = "Español", Code = "es" },
|
||||
// new LanguageInfo() { Language = SystemLanguage.Portuguese, Name = "Português", Code = "pt" },
|
||||
|
||||
// new LanguageInfo() { Language = SystemLanguage.Polish, Name = "Polski", Code = "pl" },
|
||||
// new LanguageInfo() { Language = SystemLanguage.Dutch, Name = "Nederlands", Code = "nl" },
|
||||
// new LanguageInfo() { Language = SystemLanguage.Turkish, Name = "Türkçe", Code = "tr" },
|
||||
// new LanguageInfo() { Language = SystemLanguage.Italian, Name = "Italiano", Code = "it" },
|
||||
// new LanguageInfo() { Language = SystemLanguage.Arabic, Name = "العربية", Code = "ar" }
|
||||
// new LanguageInfo() { Language = SystemLanguage.Vietnamese, Name = "Tiếng Việt", Code = "vi" },
|
||||
// new LanguageInfo() { Language = SystemLanguage.Thai, Name = "ไทย", Code = "th" },
|
||||
// new LanguageInfo() { Language = SystemLanguage.Indonesian, Name = "Bahasa Indonesia", Code = "id" },
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 自定义语言和名字映射关系
|
||||
/// </summary>
|
||||
public static readonly Dictionary<SystemLanguage, LanguageInfo> languageMap =
|
||||
new Dictionary<SystemLanguage, LanguageInfo>();
|
||||
|
||||
static LanguageConst()
|
||||
{
|
||||
languageMap.Clear();
|
||||
foreach (var languageInfo in LanguageList)
|
||||
{
|
||||
languageMap.Add(languageInfo.Language, languageInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0604103560849c7b1010b0f970f73b2
|
||||
timeCreated: 1715247928
|
||||
3
Assets/Scripts/NBC/Language/Runtime/Interfaces.meta
Normal file
3
Assets/Scripts/NBC/Language/Runtime/Interfaces.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40ba3e9743bc468898c99988fe00b001
|
||||
timeCreated: 1715248026
|
||||
27
Assets/Scripts/NBC/Language/Runtime/Interfaces/ILanguage.cs
Normal file
27
Assets/Scripts/NBC/Language/Runtime/Interfaces/ILanguage.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public interface ILanguage
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取一个key对应的结果
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
string Get(string key);
|
||||
|
||||
/// <summary>
|
||||
/// 添加一个多语言键值对
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
void AddLanguage(SystemLanguage language);
|
||||
|
||||
/// <summary>
|
||||
/// 使用某个语言,通过语言枚举
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
bool UseLanguage(SystemLanguage language);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a216923a7e634b1bb9507b63b3f4174d
|
||||
timeCreated: 1715248036
|
||||
110
Assets/Scripts/NBC/Language/Runtime/Lan.cs
Normal file
110
Assets/Scripts/NBC/Language/Runtime/Lan.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using System.Collections.Generic;
|
||||
using FairyGUI;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public static class Lan
|
||||
{
|
||||
private static LanguageManager _inst;
|
||||
|
||||
public static LanguageManager Inst
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_inst == null)
|
||||
{
|
||||
_inst = new LanguageManager();
|
||||
}
|
||||
|
||||
return _inst;
|
||||
}
|
||||
}
|
||||
|
||||
public static ILanguage Text => Inst.GetLanguageModule((int)LanguageModuleType.Text);
|
||||
|
||||
public static string Get(string key)
|
||||
{
|
||||
return Text.Get(key);
|
||||
}
|
||||
|
||||
public static string Get(string key, params object[] args)
|
||||
{
|
||||
var format = string.Format(Text.Get(key), args);
|
||||
return format;
|
||||
}
|
||||
|
||||
public static void SetLanguage(this GObject child, string key, params object[] args)
|
||||
{
|
||||
if(string.IsNullOrEmpty(key)) return;
|
||||
if (Text == null) return;
|
||||
// child.lang = key;
|
||||
|
||||
|
||||
var value = Text.Get(key);
|
||||
|
||||
if (args != null && args.Length > 0)
|
||||
{
|
||||
value = string.Format(value, args);
|
||||
// child.langArgs = args;
|
||||
}
|
||||
else
|
||||
{
|
||||
// child.langArgs = null;
|
||||
}
|
||||
|
||||
|
||||
if (child is GRichTextField richTextField)
|
||||
{
|
||||
richTextField.text = value;
|
||||
}
|
||||
else if (child is GButton button)
|
||||
{
|
||||
button.title = value;
|
||||
}
|
||||
else if (child is GLabel label)
|
||||
{
|
||||
label.title = value;
|
||||
}
|
||||
else if (child is GTextField gtextField)
|
||||
{
|
||||
gtextField.text = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetLanguageImage(this GObject obj, string key)
|
||||
{
|
||||
}
|
||||
|
||||
// public static string Get(string key)
|
||||
// {
|
||||
// if(Text == null) return key;
|
||||
// return Text.Get(key);
|
||||
// }
|
||||
//
|
||||
// public static string Get(string key, params object[] args)
|
||||
// {
|
||||
// var format = string.Format(Text.Get(key), args);
|
||||
// return format;
|
||||
// }
|
||||
|
||||
|
||||
public static string GetLanImagePath(string key)
|
||||
{
|
||||
return Inst.GetLanguageModule((int)LanguageModuleType.Image).Get(key);
|
||||
}
|
||||
|
||||
public static string GetLanFontByCurFont(string key)
|
||||
{
|
||||
if (key != null)
|
||||
return Inst.GetLanguageModule((int)LanguageModuleType.Font).Get(key);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public enum LanguageModuleType
|
||||
{
|
||||
Text = 0,
|
||||
Image = 1,
|
||||
Font = 2,
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/Language/Runtime/Lan.cs.meta
Normal file
3
Assets/Scripts/NBC/Language/Runtime/Lan.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0b198d4ac014dfd90009135df5e48ac
|
||||
timeCreated: 1715247869
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9ed5bd8dc2446288048bbf4a08ad823
|
||||
timeCreated: 1715248063
|
||||
@@ -0,0 +1,78 @@
|
||||
using System.Collections.Generic;
|
||||
using FairyGUI;
|
||||
using TMPro;
|
||||
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 = 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<Font>(fontLocation + config.RelativePath);
|
||||
// FontManager.RegisterFont(font);
|
||||
// }
|
||||
// else if (config.Type == "2")
|
||||
// {
|
||||
// TMP_FontAsset fontAsset =
|
||||
// Resources.Load<TMP_FontAsset>(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<string, string> keys = new Dictionary<string, string>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 396d5c74b8514345b8fe20c34101621c
|
||||
timeCreated: 1715248083
|
||||
@@ -0,0 +1,59 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public class LanguageImage : 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>();
|
||||
|
||||
/// <summary>
|
||||
/// 获得对应图片路径
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public string Get(string key)
|
||||
{
|
||||
if (_currentLanguageDictionary != null && _currentLanguageDictionary.TryGetValue(key, out var value))
|
||||
{
|
||||
return "Assets/ResRaw/languageImage/" + value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void AddLanguage(SystemLanguage language)
|
||||
{
|
||||
var keys = Lan.Inst.GetLanguageImageConfig(LanguageConst.languageMap[language]);
|
||||
if (keys != null)
|
||||
{
|
||||
_languages[language] = keys;
|
||||
}
|
||||
else
|
||||
{
|
||||
_languages[language] = new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseLanguage(SystemLanguage language)
|
||||
{
|
||||
if (_languages.TryGetValue(language, out var language1))
|
||||
{
|
||||
_currentLanguageDictionary = language1;
|
||||
return true;
|
||||
}
|
||||
|
||||
Debug.LogError("语言图片配置不存在");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f07e3230ea741df9793099846dd6f5d
|
||||
timeCreated: 1715248110
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public class LanguageText : 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 key;
|
||||
}
|
||||
|
||||
public void AddLanguage(SystemLanguage language)
|
||||
{
|
||||
var keys = Lan.Inst.GetLanguageConfig(LanguageConst.languageMap[language]);
|
||||
if (keys != null)
|
||||
{
|
||||
_languages[language] = keys;
|
||||
}
|
||||
else
|
||||
{
|
||||
_languages[language] = new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseLanguage(SystemLanguage language)
|
||||
{
|
||||
if (_languages.TryGetValue(language, out var language1))
|
||||
{
|
||||
_currentLanguageDictionary = language1;
|
||||
return true;
|
||||
}
|
||||
|
||||
Debug.LogError("语言包不存在");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2bbfc1f115024ce4a6cc38d5be592641
|
||||
timeCreated: 1715248144
|
||||
34
Assets/Scripts/NBC/Language/Runtime/LanguageConfig.cs
Normal file
34
Assets/Scripts/NBC/Language/Runtime/LanguageConfig.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public struct LanguageFontConfig
|
||||
{
|
||||
public string Type;
|
||||
public string Name;
|
||||
public string RelativePath;
|
||||
}
|
||||
|
||||
public class LanguageConfig
|
||||
{
|
||||
public string Key;
|
||||
private readonly Dictionary<string, string> _languages = new Dictionary<string, string>();
|
||||
|
||||
public string this[string key] => _languages.GetValueOrDefault(key, key);
|
||||
|
||||
public Dictionary<string, string>.KeyCollection Keys => _languages.Keys;
|
||||
|
||||
public void Parse(JToken row)
|
||||
{
|
||||
Key = row["key"].ToString();
|
||||
var children = row.Children();
|
||||
foreach (var child in children)
|
||||
{
|
||||
if (child is not JProperty property) continue;
|
||||
if (property.Name == "key") continue;
|
||||
_languages[property.Name] = property.Value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd21030efb0f447988cd659f8a754506
|
||||
timeCreated: 1749112259
|
||||
218
Assets/Scripts/NBC/Language/Runtime/LanguageManager.cs
Normal file
218
Assets/Scripts/NBC/Language/Runtime/LanguageManager.cs
Normal file
@@ -0,0 +1,218 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NBC.Asset;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public class LanguageManager
|
||||
{
|
||||
private string _currentCustomLanguageName = string.Empty;
|
||||
private SystemLanguage _currentLanguage;
|
||||
|
||||
private Dictionary<int, ILanguage> _lanModuleDic = new Dictionary<int, ILanguage>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 变化通知事件
|
||||
/// </summary>
|
||||
public event Action ChangeAction;
|
||||
|
||||
public LanguageManager()
|
||||
{
|
||||
LoadLanguageConfig();
|
||||
}
|
||||
|
||||
public void AddLanguageModule(int type, ILanguage languageModule)
|
||||
{
|
||||
_lanModuleDic.Add(type, languageModule);
|
||||
}
|
||||
|
||||
public ILanguage GetLanguageModule(int type)
|
||||
{
|
||||
return _lanModuleDic.GetValueOrDefault(type);
|
||||
}
|
||||
|
||||
public string GetCurrentCustomLanguageName()
|
||||
{
|
||||
return _currentCustomLanguageName;
|
||||
}
|
||||
|
||||
public SystemLanguage GetCurrentLanguage()
|
||||
{
|
||||
return _currentLanguage;
|
||||
}
|
||||
|
||||
public void AutoUseLanguage()
|
||||
{
|
||||
SystemLanguage language = Application.systemLanguage;
|
||||
if (PlayerPrefs.HasKey(LanguageConst.LanguageSaveKey))
|
||||
{
|
||||
var value = PlayerPrefs.GetInt(LanguageConst.LanguageSaveKey, -1);
|
||||
if (value >= 0)
|
||||
{
|
||||
language = (SystemLanguage)value;
|
||||
}
|
||||
}
|
||||
|
||||
var list = LanguageConst.languageMap.Values.ToList();
|
||||
var findLan = list.FindIndex(t => t.Language == language);
|
||||
if (findLan < 0)
|
||||
{
|
||||
language = SystemLanguage.English;
|
||||
}
|
||||
|
||||
UseLanguage(language);
|
||||
}
|
||||
|
||||
public void UseLanguage(SystemLanguage language)
|
||||
{
|
||||
_currentLanguage = language;
|
||||
if (LanguageConst.languageMap.TryGetValue(language, out var info))
|
||||
{
|
||||
_currentCustomLanguageName = info.Code;
|
||||
}
|
||||
|
||||
foreach (var value in _lanModuleDic.Values)
|
||||
{
|
||||
value.UseLanguage(language);
|
||||
}
|
||||
|
||||
ChangeAction?.Invoke();
|
||||
}
|
||||
|
||||
public void AddLanguage(SystemLanguage language, bool isDefault = false)
|
||||
{
|
||||
foreach (var pair in _lanModuleDic)
|
||||
{
|
||||
pair.Value.AddLanguage(language);
|
||||
}
|
||||
|
||||
if (isDefault)
|
||||
{
|
||||
UseLanguage(language);
|
||||
}
|
||||
}
|
||||
|
||||
#region config
|
||||
|
||||
private readonly Dictionary<string, LanguageConfig> _languageConfigs = new Dictionary<string, LanguageConfig>();
|
||||
private readonly Dictionary<string, string> _font2Key = new Dictionary<string, string>();
|
||||
|
||||
private readonly Dictionary<string, LanguageConfig> _languageFontConfigs =
|
||||
new Dictionary<string, LanguageConfig>();
|
||||
|
||||
private readonly Dictionary<string, LanguageConfig> _languageImagesConfigs =
|
||||
new Dictionary<string, LanguageConfig>();
|
||||
|
||||
public Dictionary<string, string> GetLanguageConfig(LanguageInfo languageInfo)
|
||||
{
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
foreach (var key in _languageConfigs.Keys)
|
||||
{
|
||||
var value = _languageConfigs[key];
|
||||
dic[key] = value[languageInfo.Code];
|
||||
}
|
||||
|
||||
return dic;
|
||||
}
|
||||
|
||||
public Dictionary<string, LanguageFontConfig> GetLanguageFontConfig(LanguageInfo languageInfo)
|
||||
{
|
||||
if (_font2Key.Count != _languageFontConfigs.Count)
|
||||
{
|
||||
foreach (var fKey in _languageFontConfigs.Keys)
|
||||
{
|
||||
var config = _languageFontConfigs[fKey];
|
||||
foreach (var key in config.Keys)
|
||||
{
|
||||
var result = config[key];
|
||||
if (result != null)
|
||||
{
|
||||
string[] strs = result.Split(",");
|
||||
_font2Key[strs[1]] = fKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<string, LanguageFontConfig> dic = new Dictionary<string, LanguageFontConfig>();
|
||||
foreach (var key in _languageFontConfigs.Keys)
|
||||
{
|
||||
var config = _languageFontConfigs[key];
|
||||
string result = config[languageInfo.Code];
|
||||
if (result != null)
|
||||
{
|
||||
string[] strs = result.Split(",");
|
||||
var result2 = new LanguageFontConfig()
|
||||
{
|
||||
Type = strs[0],
|
||||
Name = key,
|
||||
RelativePath = strs[1],
|
||||
};
|
||||
dic[key] = result2;
|
||||
}
|
||||
}
|
||||
|
||||
return dic;
|
||||
}
|
||||
|
||||
|
||||
public Dictionary<string, string> GetLanguageImageConfig(LanguageInfo languageInfo)
|
||||
{
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
foreach (var key in _languageImagesConfigs.Keys)
|
||||
{
|
||||
var value = _languageImagesConfigs[key];
|
||||
dic[key] = value[languageInfo.Code];
|
||||
}
|
||||
|
||||
return dic;
|
||||
}
|
||||
|
||||
public Dictionary<string, string> GetFont2KeyDic()
|
||||
{
|
||||
return _font2Key;
|
||||
}
|
||||
|
||||
private void LoadLanguageConfig()
|
||||
{
|
||||
_languageConfigs.Clear();
|
||||
var textAsset = Assets.Load<TextAsset>("Config/language");
|
||||
if (textAsset)
|
||||
{
|
||||
var jToken = JObject.Parse(textAsset.text);
|
||||
foreach (var obj in jToken)
|
||||
{
|
||||
switch (obj.Key)
|
||||
{
|
||||
case "language":
|
||||
LoadLanguageConfig(obj.Value, _languageConfigs);
|
||||
break;
|
||||
case "languageFont":
|
||||
LoadLanguageConfig(obj.Value, _languageFontConfigs);
|
||||
break;
|
||||
case "languageImage":
|
||||
LoadLanguageConfig(obj.Value, _languageImagesConfigs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadLanguageConfig(JToken token, Dictionary<string, LanguageConfig> dictionary)
|
||||
{
|
||||
if (token is not JArray jArray) return;
|
||||
foreach (var j in jArray)
|
||||
{
|
||||
var config = new LanguageConfig();
|
||||
config.Parse(j);
|
||||
dictionary[config.Key] = config;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ec1923616334332b11de9ace7adb03a
|
||||
timeCreated: 1715247890
|
||||
18
Assets/Scripts/NBC/Language/Runtime/NBC.Lan.asmdef
Normal file
18
Assets/Scripts/NBC/Language/Runtime/NBC.Lan.asmdef
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "NBC.Lan",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:8c8f9d96103e94a7da84b012fd7e9f13",
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:3f4a88279c0696a488a2e08f8bccf903"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Assets/Scripts/NBC/Language/Runtime/NBC.Lan.asmdef.meta
Normal file
7
Assets/Scripts/NBC/Language/Runtime/NBC.Lan.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8beb767f9f7a66f4e87dd9db57cdd64e
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user