62 lines
1.2 KiB
C#
62 lines
1.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Localization
|
|
{
|
|
[RequireComponent(typeof(Text))]
|
|
public class LocalizedText: MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private int locId = -1;
|
|
[SerializeField]
|
|
private bool upperCase = false;
|
|
|
|
private Text _textComponent = null;
|
|
|
|
public bool IsTextEmpty
|
|
{
|
|
get { return string.IsNullOrEmpty(_textComponent.text); }
|
|
}
|
|
|
|
public bool isTextLocalized {
|
|
get { return (locId != -1); }
|
|
}
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
_textComponent = GetComponent<Text>();
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
SetText();
|
|
}
|
|
|
|
public void SetText(string text)
|
|
{
|
|
if(upperCase)
|
|
_textComponent.text = text.ToUpper();
|
|
else
|
|
_textComponent.text = text;
|
|
|
|
gameObject.SetActive(!IsTextEmpty);
|
|
}
|
|
|
|
public void SetLocId(int id)
|
|
{
|
|
locId = id;
|
|
|
|
if (_textComponent != null)
|
|
SetText();
|
|
}
|
|
|
|
private void SetText()
|
|
{
|
|
if(locId == -1)
|
|
return;
|
|
|
|
SetText(LocalizationManager.Instance.GetLocalizedString(locId));
|
|
}
|
|
}
|
|
}
|