更改了文件结构
This commit is contained in:
57
Src/Unity/Scripts/UX/Core/UXButton.cs
Normal file
57
Src/Unity/Scripts/UX/Core/UXButton.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user