Skip to content

Instantly share code, notes, and snippets.

@LLarean
Created July 25, 2024 14:08
Show Gist options
  • Save LLarean/0470e67c14834c3f48aa83d42d1ea411 to your computer and use it in GitHub Desktop.
Save LLarean/0470e67c14834c3f48aa83d42d1ea411 to your computer and use it in GitHub Desktop.
using TMPro;
using UnityEngine;
namespace Assets.SimpleLocalization.Scripts
{
/// <summary>
/// Localize TMP_Text component.
/// </summary>
[RequireComponent(typeof(TMP_Text))]
public class LocalizedTMP : MonoBehaviour
{
[SerializeField] private string LocalizationKey;
private void Start()
{
Localize();
LocalizationManager.OnLocalizationChanged += Localize;
}
private void OnDestroy()
{
LocalizationManager.OnLocalizationChanged -= Localize;
}
private void Localize()
{
GetComponent<TMP_Text>().text = LocalizationManager.Localize(LocalizationKey);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment