HKI Core
HKIVarToggle.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEngine.Events;
3 
4 namespace HKI.Core.Variables
5 {
11  public class HKIVarToggle : MonoBehaviour
12  {
13  // Class
14  [System.Serializable]
15  public class HKIVarToggleUE : UnityEvent<bool> { }
16 
17  // Public variable
18  [SerializeField] Boolean Boolean = null;
19 
20  public HKIVarToggleUE OnValueChanged = new HKIVarToggleUE();
21 
22  // OnEnable function
23  void OnEnable()
24  {
25  if (Boolean != null)
26  {
27  Boolean.OnValueChanged += ValueChangedFunction;
28  ValueChangedFunction();
29  }
30  else
31  Debug.LogWarning("This HKIVarToggle has no boolean value.");
32  }
33 
34  // OnDisable function
35  void OnDisable()
36  {
37  if (Boolean != null)
38  Boolean.OnValueChanged -= ValueChangedFunction;
39  }
40 
42  {
43  OnValueChanged.Invoke(Boolean.Value);
44  }
45  }
46 }
This MonoBehaviour pathes the new boolean value to a function if the value changed. This could be used for enabling and disabling GameObjects by only using the editor and no code (like using a UI Button).
Definition: HKIVarToggle.cs:11
Implementation of a boolean value as a HKIVar via HKIVarGeneric.
Definition: Boolean.cs:16