HKI Core
UILocalizeText.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEngine.UI;
3 using System.Reflection;
4 using HKI.Core.Loc;
5 
6 namespace HKI.Core.UI
7 {
11  [AddComponentMenu("HKI/UI/UILocalizeText")]
12  [DisallowMultipleComponent]
13  public class UILocalizeText : MonoBehaviour
14  {
15  // Public variables
16  [Header("General Properties")]
17  [SerializeField] Language Language = null;
18  [SerializeField] TextLocalization TextLocalization = null;
19 
20  // Private variables
22 
23  // Awake function
24  void Awake()
25  {
26  text = new TMProAndUGUITextAccessor(gameObject);
27  }
28 
29  // OnEnable function
30  void OnEnable()
31  {
32  ChangeText();
33 
34  if(Language != null)
35  Language.OnValueChanged += ChangeText;
36  }
37 
38  // OnDisable function
39  void OnDisable()
40  {
41  if(Language != null)
42  Language.OnValueChanged -= ChangeText;
43  }
44 
45  // Helper functions
46  void ChangeText()
47  {
48  if(TextLocalization != null)
49  text.ChangeText(TextLocalization.GetText(Language));
50  }
51  }
52 }
This ScriptableObject contains as a container for all text localization information.
string GetText(Language language)
This function returns the string in a specific language. If there is no localization element in the r...
This class allows the use of the standard Unity UI Text component and the TextMeshPro component witho...
Special Variable enables the use of the SystemLanguage data type as a variable of the settings system...
Definition: Language.cs:13
This MonoBehaviour localize a Unity UIText or a TextMeshPro text component. It also updates the text ...