LocalizeTMPro.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using UnityEngine;
  2. using TMPro;
  3. using UnityEngine.UI;
  4. public class LocalizeTMPro : MonoBehaviour
  5. {
  6. [SerializeField] TMP_FontAsset _fontMaterial_ENG;
  7. [SerializeField] TMP_FontAsset _fontMaterial_JPN;
  8. [SerializeField] Font _font_ENG;
  9. [SerializeField] Font _font_JPN;
  10. [SerializeField] int _fontSize_ENG = -1;
  11. [SerializeField] int _fontSize_JPN = -1;
  12. [TextArea] public string _text_ENG;
  13. [TextArea] public string _text_JPN;
  14. TextMeshProUGUI _textMeshPro = null;
  15. Text _text = null;
  16. int _updateFrame = 50;
  17. int _timerCount = 0;
  18. void ChangeText()
  19. {
  20. if (_textMeshPro == null && _text == null)
  21. {
  22. return;
  23. }
  24. if (ContinuousController.instance != null)
  25. {
  26. switch (ContinuousController.instance.language)
  27. {
  28. case Language.ENG:
  29. if (_textMeshPro != null)
  30. {
  31. if (_fontMaterial_ENG != null)
  32. {
  33. _textMeshPro.font = _fontMaterial_ENG;
  34. }
  35. if (!string.IsNullOrEmpty(_text_ENG))
  36. {
  37. _textMeshPro.text = _text_ENG;
  38. }
  39. if (_fontSize_ENG > 0)
  40. {
  41. _textMeshPro.fontSize = _fontSize_ENG;
  42. }
  43. }
  44. else if (_text != null)
  45. {
  46. if (_font_ENG != null)
  47. {
  48. _text.font = _font_ENG;
  49. }
  50. if (!string.IsNullOrEmpty(_text_ENG))
  51. {
  52. _text.text = _text_ENG;
  53. }
  54. if (_fontSize_ENG > 0)
  55. {
  56. _text.fontSize = _fontSize_ENG;
  57. }
  58. }
  59. break;
  60. case Language.JPN:
  61. if (_textMeshPro != null)
  62. {
  63. if (_fontMaterial_ENG != null)
  64. {
  65. _textMeshPro.font = _fontMaterial_JPN;
  66. }
  67. if (!string.IsNullOrEmpty(_text_JPN))
  68. {
  69. _textMeshPro.text = _text_JPN;
  70. }
  71. if (_fontSize_JPN > 0)
  72. {
  73. _textMeshPro.fontSize = _fontSize_JPN;
  74. }
  75. }
  76. else if (_text != null)
  77. {
  78. if (_font_JPN != null)
  79. {
  80. _text.font = _font_JPN;
  81. }
  82. if (!string.IsNullOrEmpty(_text_JPN))
  83. {
  84. _text.text = _text_JPN;
  85. }
  86. if (_fontSize_JPN > 0)
  87. {
  88. _text.fontSize = _fontSize_JPN;
  89. }
  90. }
  91. break;
  92. }
  93. }
  94. }
  95. void Awake()
  96. {
  97. _textMeshPro = GetComponent<TextMeshProUGUI>();
  98. _text = GetComponent<Text>();
  99. }
  100. private void OnEnable()
  101. {
  102. ChangeText();
  103. }
  104. void Update()
  105. {
  106. #region update per a few frames
  107. _timerCount++;
  108. if (_timerCount < _updateFrame)
  109. {
  110. return;
  111. }
  112. else
  113. {
  114. _timerCount = 0;
  115. }
  116. #endregion
  117. ChangeText();
  118. }
  119. }