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

41 lines
1.0 KiB
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 Kill.Managers;
using UnityEngine.UI;
using System;
namespace Kill.UI.Components
{
public class MultiLanguageText : MonoBehaviour
{
[Tooltip("对应LanguageConfig.json中的键")]
public string textKey; // 在Inspector中设置如"btn_start"
private Text textComponent;
Action<string> callback;
string callbackStr;
private void Awake()
{
textComponent = GetComponent<Text>();
UpdateText();
}
// 更新文本(语言切换时调用)
public void UpdateText()
{
if (!string.IsNullOrEmpty(textKey))
{
if (textComponent != null)
{
textComponent.text = LanguageManager.Instance.GetLanguage(textKey);
}
}
callback?.Invoke(callbackStr);
}
public void SetCallBack(Action<string> action,string str)
{
callback=action;
callbackStr=str;
}
}
}