|
using UnityEngine;
|
using UnityEngine.UI;
|
using TMPro;
|
|
/// <summary>
|
/// 修改文字脚本
|
/// </summary>
|
public class LocalizationText : MonoBehaviour
|
{
|
[SerializeField, Header("Langkey")]
|
private string key = " ";
|
private Text _text;
|
private TextMeshProUGUI _textMeshPro;
|
void Awake()
|
{
|
LanguageManager.onLanguageChanged += onLanguageChanged;
|
}
|
|
private void OnDestroy()
|
{
|
LanguageManager.onLanguageChanged -= onLanguageChanged;
|
}
|
/// <summary>
|
/// Start is called on the frame when a script is enabled just before
|
/// any of the Update methods is called the first time.
|
/// </summary>
|
void Start()
|
{
|
_text = GetComponent<Text>();
|
_textMeshPro = GetComponent<TextMeshProUGUI>();
|
onLanguageChanged();
|
}
|
|
void onLanguageChanged()
|
{
|
if (_text != null)
|
{
|
_text.text = MultiLangConst.GetValue(key);
|
}
|
else if (_textMeshPro != null)
|
{
|
_textMeshPro.text = MultiLangConst.GetValue(key);
|
}
|
}
|
}
|