40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using UnityEngine.Events;
|
|
namespace BITKit.UX
|
|
{
|
|
public class UXToggle : UXElement<Toggle>
|
|
{
|
|
[Header(Constant.Header.Events)]
|
|
public UnityEvent<bool> 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);
|
|
}
|
|
}
|
|
} |