Passion & UI
This commit is contained in:
@@ -6,7 +6,7 @@ namespace SLSUtilities.General
|
||||
public class Singleton<T> : SerializedMonoBehaviour where T : MonoBehaviour
|
||||
{
|
||||
protected static T instance;
|
||||
public static T Instance => instance == null ? FindFirstObjectByType<T>() : instance;
|
||||
public static T Instance => instance;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
|
||||
@@ -1,18 +1,35 @@
|
||||
using I2.Loc;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Localization.Settings;
|
||||
|
||||
namespace SLSUtilities.General
|
||||
{
|
||||
public static class StringExtension
|
||||
{
|
||||
public static string Localize(this string original)
|
||||
/// <summary>
|
||||
/// 根据 Key 从指定 Table 中获取本地化文本。
|
||||
/// 若本地化系统尚未初始化或 Key 不存在,则原样返回。
|
||||
/// </summary>
|
||||
public static string Localize(this string key, string tableName)
|
||||
{
|
||||
if (LocalizationManager.TryGetTranslation(original, out string translated))
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
return translated;
|
||||
return key;
|
||||
}
|
||||
|
||||
return original;
|
||||
if (!LocalizationSettings.HasSettings ||
|
||||
LocalizationSettings.SelectedLocale == null)
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
string result = LocalizationSettings.StringDatabase.GetLocalizedString(tableName, key);
|
||||
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user