killapp/Assets/Scripts/UI/Components/MultiLanguageText.cs

41 lines
1.0 KiB
C#
Raw Permalink Normal View History

2025-11-18 09:18:48 +08:00
using UnityEngine;
2026-04-16 14:57:19 +08:00
using Kill.Managers;
2026-03-30 16:25:00 +08:00
using UnityEngine.UI;
2026-04-24 16:57:44 +08:00
using System;
2025-11-18 09:18:48 +08:00
2026-04-16 14:57:19 +08:00
namespace Kill.UI.Components
{
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"
private Text textComponent;
2026-04-24 16:57:44 +08:00
Action<string> callback;
string callbackStr;
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>();
2026-04-16 14:57:19 +08:00
UpdateText();
2026-03-30 16:25:00 +08:00
}
// 更新文本(语言切换时调用)
public void UpdateText()
{
if (!string.IsNullOrEmpty(textKey))
{
if (textComponent != null)
2026-03-30 16:25:00 +08:00
{
textComponent.text = LanguageManager.Instance.GetLanguage(textKey);
}
}
2026-04-24 16:57:44 +08:00
callback?.Invoke(callbackStr);
}
public void SetCallBack(Action<string> action,string str)
{
callback=action;
callbackStr=str;
2025-11-18 09:18:48 +08:00
}
}
}