31 lines
903 B
C#
31 lines
903 B
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.Localization.Components;
|
|
|
|
namespace AibisDream
|
|
{
|
|
[RequireComponent(typeof(TMP_Text))]
|
|
[RequireComponent(typeof(LocalizeStringEvent))]
|
|
public class LocalizedText : MonoBehaviour
|
|
{
|
|
private TMP_Text _text;
|
|
private LocalizeStringEvent _localizeEvent;
|
|
|
|
private void OnUpdateString(string text)
|
|
{
|
|
var textArr = text.Split(":");
|
|
_text.text = textArr.Length > 1 ? textArr[1].Trim() : text;
|
|
}
|
|
|
|
public void SetLocalizedText(string table, string entry)
|
|
{
|
|
_text = GetComponent<TMP_Text>();
|
|
_localizeEvent = GetComponent<LocalizeStringEvent>();
|
|
|
|
_localizeEvent.OnUpdateString.AddListener(OnUpdateString);
|
|
|
|
_localizeEvent.SetTable(table);
|
|
_localizeEvent.SetEntry(entry);
|
|
}
|
|
}
|
|
} |