LocaleUI.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using TMPro;
  2. using UnityEngine;
  3. public static class LocaleUI
  4. {
  5. public static void SetText(Transform root, string path, string key)
  6. {
  7. if (root == null || string.IsNullOrEmpty(key))
  8. return;
  9. TMP_Text text = string.IsNullOrEmpty(path)
  10. ? root.GetComponent<TMP_Text>()
  11. : UIViewUtility.Text(root, path);
  12. if (text != null)
  13. text.text = L.Get(key);
  14. }
  15. public static void SetFormat(Transform root, string path, string key, params object[] args)
  16. {
  17. if (root == null || string.IsNullOrEmpty(key))
  18. return;
  19. TMP_Text text = string.IsNullOrEmpty(path)
  20. ? root.GetComponent<TMP_Text>()
  21. : UIViewUtility.Text(root, path);
  22. if (text != null)
  23. text.text = L.F(key, args);
  24. }
  25. public static void ApplyLocalizedTmp(Transform root)
  26. {
  27. if (root == null)
  28. return;
  29. var items = root.GetComponentsInChildren<LocalizedTMP>(true);
  30. for (int i = 0; i < items.Length; i++)
  31. items[i].Apply();
  32. }
  33. }