add project files
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace OHM.UnityToolkit.Localization
|
||||
{
|
||||
public class LocalizedText : MonoBehaviour
|
||||
{
|
||||
public string key;
|
||||
|
||||
public TextWrapper text;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
text = GetComponent<TextWrapper>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
ApplyLocalization();
|
||||
LocalizationManager.Instance.OnLangChanged.AddListener(ApplyLocalization);
|
||||
}
|
||||
|
||||
public void ChangeKey(string key)
|
||||
{
|
||||
this.key = key;
|
||||
ApplyLocalization();
|
||||
}
|
||||
|
||||
public void ApplyLocalization()
|
||||
{
|
||||
SetText(string.IsNullOrEmpty(key)
|
||||
? string.Empty
|
||||
: LocalizationUtils.Localize(LocalizationManager.Instance.CurrentLocale, key));
|
||||
}
|
||||
|
||||
private void SetText(string content)
|
||||
{
|
||||
if (text != null)
|
||||
{
|
||||
text.text = content;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user