Created
July 25, 2024 14:08
-
-
Save LLarean/0470e67c14834c3f48aa83d42d1ea411 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 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