TextLocalization.cs 1020 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. [RequireComponent(typeof(Text))]
  5. public class TextLocalization : MonoBehaviour {
  6. public string key;
  7. private string replaceText;
  8. void Start() {
  9. // Get the string value from localization manager from key
  10. // and set the text component text value to the returned string value
  11. string text = LocalizationManager.Instance.GetText(key);
  12. text = text.Replace("\\n", Environment.NewLine);
  13. if (replaceText != null) {
  14. text = String.Format(text, replaceText);
  15. }
  16. GetComponent<Text>().text = text;
  17. }
  18. public void UpdateText() {
  19. string text = LocalizationManager.Instance.GetText(key);
  20. text = text.Replace("\\n", Environment.NewLine);
  21. if (replaceText != null) {
  22. text = String.Format(text, replaceText);
  23. }
  24. GetComponent<Text>().text = text;
  25. }
  26. public void SetReplaceText(string value) {
  27. replaceText = value;
  28. }
  29. }