2021-11-23 15:48:22 +08:00

56 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts.UI.Control
{
[RequireComponent(typeof(Text))]
public class PFUIText : PFUIComponentBase
{
public string key;
private Text text;
public string Text
{
get
{
return text.text;
}
set
{
text.text = value;
}
}
protected void Awake()
{
text = this.transform.GetComponent<Text>();
if (string.IsNullOrEmpty(key))
{
key = text.text;//默认英文内容为key值
}
}
protected void Start()
{
//Debug.Log(text.text);
if (App.LanguageManager != null && App.LanguageManager.ContainsKey(key))
{
//Debug.Log(text.text);
text.text = App.LanguageManager[key];
}
App.ChangeLanguageEvent += App_ChangeLanguageEvent;
}
private void App_ChangeLanguageEvent()
{
if (App.LanguageManager != null && App.LanguageManager.ContainsKey(text.text))
{
text.text = App.LanguageManager[key];
}
}
}
}