using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; using UnityEngine.Events; namespace BITKit.UX { public class UXToggle : UXElement { [Header(Constant.Header.Events)] public UnityEvent onToggle = new(); public UnityEvent onChecked = new(); public UnityEvent onDecheck = new(); public override void OnStart() { base.OnStart(); visualElement.RegisterValueChangedCallback(x => { onToggle.Invoke(x.newValue); if (x.newValue) { onChecked.Invoke(); } else { onDecheck.Invoke(); } }); } public override bool Get() { return visualElement.value; } public override void Set(bool active) { onToggle.Invoke(active); visualElement.SetValueWithoutNotify(active); } } }