Created
September 29, 2020 01:03
-
-
Save kalineh/8a181cb8537a13862285a09eaff09308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using TMPro; | |
public class LocalizationDynamic | |
: MonoBehaviour | |
{ | |
public string key; | |
private TMP_Text text; | |
public void OnEnable() | |
{ | |
Tracked<LocalizationDynamic>.OnEnable(this); | |
text = GetComponent<TMP_Text>(); | |
Translate(); | |
} | |
public void OnDisable() | |
{ | |
Tracked<LocalizationDynamic>.OnDisable(this); | |
} | |
public void Translate() | |
{ | |
if (key == null) | |
return; | |
var value = Localization.Instance.Get(key); | |
text.text = value; | |
} | |
#if UNITY_EDITOR | |
public void OnValidate() | |
{ | |
var text = GetComponent<TMP_Text>(); | |
UnityEditor.Undo.RecordObject(text, "Translate"); | |
text.text = key; | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment