33 lines
881 B
C#
33 lines
881 B
C#
using UnityEngine;
|
||
using TMPro;
|
||
namespace Kill.UI
|
||
{
|
||
[RequireComponent(typeof(TextMeshProUGUI))] // 依赖Text组件(TMP或UGUI)
|
||
public class MultiLanguageText : MonoBehaviour
|
||
{
|
||
[Tooltip("对应LanguageConfig.json中的键")]
|
||
public string textKey; // 在Inspector中设置,如"btn_start"
|
||
|
||
private TextMeshProUGUI textComponent; // 若用UGUI,改为Text
|
||
|
||
private void Awake()
|
||
{
|
||
textComponent = GetComponent<TextMeshProUGUI>();
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
UpdateText(); // 初始化显示
|
||
}
|
||
|
||
// 更新文本(语言切换时调用)
|
||
public void UpdateText()
|
||
{
|
||
if (!string.IsNullOrEmpty(textKey))
|
||
{
|
||
textComponent.text = Base.LanguageManager.Instance.GetLanguage(textKey);
|
||
}
|
||
}
|
||
}
|
||
}
|