Skip to content

Instantly share code, notes, and snippets.

@kalineh
Created September 29, 2020 01:03
Show Gist options
  • Save kalineh/8a181cb8537a13862285a09eaff09308 to your computer and use it in GitHub Desktop.
Save kalineh/8a181cb8537a13862285a09eaff09308 to your computer and use it in GitHub Desktop.
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