Files
aibis-dream/Assets/Scripts/UI/DialogUI/LocalizedText.cs
T
2025-05-20 17:05:56 +08:00

39 lines
1.0 KiB
C#

using AibisDream.Utility;
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;
public bool isLineText = true;
public string template = "{0}";
private void OnUpdateString(string text)
{
if (isLineText)
{
text = CommonUtil.RemoveName(text);
}
_text.text = string.Format(template, 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);
}
}
}