2025-11-18 09:18:48 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using TMPro;
|
2026-03-30 16:25:00 +08:00
|
|
|
|
using Kill.Base;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
namespace Kill.UI
|
2025-11-18 09:18:48 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-03-30 16:25:00 +08:00
|
|
|
|
public class MultiLanguageText : MonoBehaviour
|
2025-11-18 09:18:48 +08:00
|
|
|
|
{
|
2026-03-30 16:25:00 +08:00
|
|
|
|
[Tooltip("对应LanguageConfig.json中的键")]
|
|
|
|
|
|
public string textKey; // 在Inspector中设置,如"btn_start"
|
2025-11-18 09:18:48 +08:00
|
|
|
|
|
2026-03-30 16:25:00 +08:00
|
|
|
|
private TextMeshProUGUI textComponentPro; // 若用UGUI,改为Text
|
|
|
|
|
|
private Text textComponent;
|
2025-11-18 09:18:48 +08:00
|
|
|
|
|
2026-03-30 16:25:00 +08:00
|
|
|
|
private void Awake()
|
2025-11-18 09:18:48 +08:00
|
|
|
|
{
|
2026-03-30 16:25:00 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-11-18 09:18:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|