killapp/Assets/Scripts/Base/MultiLanguageText.cs
“虞渠成” 471f4c8962 init
2025-11-18 09:18:48 +08:00

33 lines
881 B
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 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);
}
}
}
}