DownClickable.cs 906 B

123456789101112131415161718192021222324252627282930313233343536
  1. using UnityEngine.UIElements;
  2. namespace UnityEditor.VFX.UI
  3. {
  4. class DownClickable : MouseManipulator
  5. {
  6. public event System.Action clicked;
  7. // Click-once type constructor
  8. public DownClickable(System.Action handler)
  9. {
  10. clicked = handler;
  11. activators.Add(new ManipulatorActivationFilter { button = MouseButton.LeftMouse });
  12. }
  13. protected override void RegisterCallbacksOnTarget()
  14. {
  15. target.RegisterCallback<MouseDownEvent>(OnMouseDown);
  16. }
  17. protected override void UnregisterCallbacksFromTarget()
  18. {
  19. target.UnregisterCallback<MouseDownEvent>(OnMouseDown);
  20. }
  21. protected void OnMouseDown(MouseDownEvent evt)
  22. {
  23. if (clicked != null)
  24. {
  25. clicked();
  26. evt.StopPropagation();
  27. }
  28. }
  29. }
  30. }