59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
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;
|
|
}
|
|
}
|
|
} |