HKI Core
UIValueText.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEngine.UI;
3 using HKI.Core.Variables;
4 
5 namespace HKI.Core.UI
6 {
10  [AddComponentMenu("HKI/UI/UIValueText")]
11  [DisallowMultipleComponent]
12  public class UIValueText : MonoBehaviour
13  {
14  // Public variables
15  [Header("General Properties")]
16  [SerializeField] HKIVar Variable = null;
17 
18  // Private variables
19  TMProAndUGUITextAccessor valueText = null;
20 
21  // Awake function
22  void Awake()
23  {
24  if(Variable == null)
25  {
26  Debug.LogError("(UIValueText)" + name + " there isn't a variable attached to this value text!");
27  return;
28  }
29 
30  valueText = new TMProAndUGUITextAccessor(gameObject);
31  }
32 
33  // OnEnable function
34  void OnEnable()
35  {
36  UpdateText();
37 
38  if(Variable != null)
39  Variable.OnValueChanged += UpdateText;
40  }
41 
42  // OnDisable function
43  void OnDisable()
44  {
45  if(Variable != null)
46  Variable.OnValueChanged -= UpdateText;
47  }
48 
49  // Interface function
50  public void UpdateText()
51  {
52  if(Variable != null)
53  valueText.ChangeText(Variable.ToString());
54  }
55  }
56 }
System.Action OnValueChanged
Definition: HKIVar.cs:15
This MonoBehaviour set the text of an Unity UIText or a TextMeshPro text component to the value of a ...
Definition: UIValueText.cs:12
This abstract class of a ScriptableObject is provides child classes with on value changed callback ca...
Definition: HKIVar.cs:12
This class allows the use of the standard Unity UI Text component and the TextMeshPro component witho...