52 lines
973 B
C#
52 lines
973 B
C#
|
|
using Framework;
|
||
|
|
using TMPro;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
|
||
|
|
[RequireComponent(typeof(TMP_Text))]
|
||
|
|
public class LocalizeText: MonoBehaviour
|
||
|
|
{
|
||
|
|
public string text_key;
|
||
|
|
private void Start()
|
||
|
|
{
|
||
|
|
Localize();
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
void Localize()
|
||
|
|
{
|
||
|
|
if (text_key == null || text_key.Length <= 0) return;
|
||
|
|
var txt = GetComponent<TMP_Text>();
|
||
|
|
if (txt)
|
||
|
|
{
|
||
|
|
txt.text = StringManager.Instance.GetLocalizeTextByKey(text_key);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#if UNITY_EDITOR
|
||
|
|
|
||
|
|
private void OnValidate()
|
||
|
|
{
|
||
|
|
LocalizeOnInspector();
|
||
|
|
}
|
||
|
|
|
||
|
|
void LocalizeOnInspector()
|
||
|
|
{
|
||
|
|
string text = "";
|
||
|
|
if (text_key != null && text_key.Length > 0)
|
||
|
|
{
|
||
|
|
text = EditorTableManager.GetLocalizeText(text_key);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (text != null)
|
||
|
|
{
|
||
|
|
var txt = GetComponent<TMP_Text>();
|
||
|
|
if (txt)
|
||
|
|
{
|
||
|
|
txt.text = text;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
}
|