Scrollable.cs 753 B

1234567891011121314151617181920212223242526272829303132
  1. using UnityEngine;
  2. using System;
  3. using UnityEngine.UIElements;
  4. namespace UnityEditor.ShaderGraph.Drawing
  5. {
  6. class Scrollable : MouseManipulator
  7. {
  8. Action<float> m_Handler;
  9. public Scrollable(Action<float> handler)
  10. {
  11. m_Handler = handler;
  12. }
  13. protected override void RegisterCallbacksOnTarget()
  14. {
  15. target.RegisterCallback<WheelEvent>(HandleMouseWheelEvent);
  16. }
  17. protected override void UnregisterCallbacksFromTarget()
  18. {
  19. target.UnregisterCallback<WheelEvent>(HandleMouseWheelEvent);
  20. }
  21. void HandleMouseWheelEvent(WheelEvent evt)
  22. {
  23. m_Handler(evt.delta.y);
  24. evt.StopPropagation();
  25. }
  26. }
  27. }