Files
Continentis/Assets/Scripts/ScriptExtensions/General/StringExtension.cs
SoulliesOfficial 40660b41e0 角色死亡
2025-12-12 01:37:30 -05:00

44 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using I2.Loc;
using UnityEngine;
namespace SLSFramework.General
{
public static class StringExtension
{
/// <summary>
/// 本地化字符串,不使用参数替换
/// </summary>
/// <param name="original">原始字符串</param>
/// <returns></returns>
public static string Localize(this string original)
{
if (LocalizationManager.TryGetTranslation(original, out string translated))
{
return translated;
}
return original;
}
/// <summary>
/// 本地化字符串使用指定的根GameObject进行i2Loc参数替换
/// </summary>
/// <param name="original">原始字符串</param>
/// <param name="rootGameObject">用于参数替换含有LocalizationParamsManager的根GameObject设为null则表明使用全局参数</param>
/// <returns></returns>
public static string Localize(this string original, GameObject rootGameObject)
{
if (rootGameObject != null && rootGameObject.GetComponent<LocalizationParamsManager>() == null)
{
throw new System.ArgumentException("The provided rootGameObject does not contain a LocalizationParamsManager component.");
}
if (LocalizationManager.TryGetTranslation(original, out string translated, true, 0, true, true, rootGameObject))
{
return translated;
}
return original;
}
}
}