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