57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using UnityEngine.Events;
|
|
namespace BITKit.UX
|
|
{
|
|
public class UXButton : UXElement<Button>
|
|
{
|
|
[Header(Constant.Header.Settings)]
|
|
public bool allowRightClick;
|
|
[Header(Constant.Header.Events)]
|
|
public UnityEvent onClick = new();
|
|
public UnityEvent onRightClick = new();
|
|
public override void OnStart()
|
|
{
|
|
try
|
|
{
|
|
visualElement.clicked += Click;
|
|
}
|
|
catch (System.Exception)
|
|
{
|
|
throw;
|
|
}
|
|
if (allowRightClick)
|
|
{
|
|
foreach (var x in visualElement.Children())
|
|
{
|
|
x.pickingMode = PickingMode.Ignore;
|
|
}
|
|
visualElement.RegisterCallback<MouseDownEvent>(OnMouseDown);
|
|
visualElement.RegisterCallback<MouseUpEvent>(OnMouseUp);
|
|
}
|
|
//visualElement.AddManipulator(new ContextualMenuManipulator(RightClick));
|
|
}
|
|
public override void Set(bool active)
|
|
{
|
|
base.Set(active);
|
|
visualElement.SetEnabled(active);
|
|
}
|
|
void Click()
|
|
{
|
|
onClick.Invoke();
|
|
}
|
|
void OnMouseDown(MouseDownEvent mouseEvent)
|
|
{
|
|
if (mouseEvent.button is 1)
|
|
{
|
|
onRightClick.Invoke();
|
|
}
|
|
}
|
|
void OnMouseUp(MouseUpEvent mouseEvent)
|
|
{
|
|
|
|
}
|
|
}
|
|
} |