UI换了很多,spine主视觉停用
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(TMP_Text))]
|
||||
public class LocalizedTMPText : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private string localizationKey;
|
||||
[TextArea]
|
||||
[SerializeField] private string fallbackText;
|
||||
|
||||
private TMP_Text _tmp;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_tmp = GetComponent<TMP_Text>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
LocalizationService.EnsureInitialized();
|
||||
LocalizationService.LanguageChanged += HandleLanguageChanged;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
LocalizationService.LanguageChanged -= HandleLanguageChanged;
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if (_tmp == null)
|
||||
{
|
||||
_tmp = GetComponent<TMP_Text>();
|
||||
}
|
||||
|
||||
if (_tmp == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string fallback = string.IsNullOrEmpty(fallbackText) ? _tmp.text : fallbackText;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(localizationKey))
|
||||
{
|
||||
_tmp.text = LocalizationService.LocalizeLiteral(fallback);
|
||||
return;
|
||||
}
|
||||
|
||||
if (LocalizationService.TryGet(localizationKey, out string localized))
|
||||
{
|
||||
_tmp.text = localized;
|
||||
return;
|
||||
}
|
||||
|
||||
_tmp.text = LocalizationService.LocalizeLiteral(fallback);
|
||||
}
|
||||
|
||||
private void HandleLanguageChanged(string languageCode)
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user