ClickAction.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.U2D.Path.GUIFramework
  4. {
  5. public class ClickAction : HoveredControlAction
  6. {
  7. private int m_Button;
  8. private bool m_UseEvent;
  9. public int clickCount = 1;
  10. public Action<IGUIState, Control> onClick;
  11. private int m_ClickCounter = 0;
  12. public ClickAction(Control control, int button, bool useEvent = true) : base(control)
  13. {
  14. m_Button = button;
  15. m_UseEvent = useEvent;
  16. }
  17. protected override bool GetTriggerContidtion(IGUIState guiState)
  18. {
  19. if (guiState.mouseButton == m_Button && guiState.eventType == EventType.MouseDown)
  20. {
  21. if (guiState.clickCount == 1)
  22. m_ClickCounter = 0;
  23. ++m_ClickCounter;
  24. if (m_ClickCounter == clickCount)
  25. return true;
  26. }
  27. return false;
  28. }
  29. protected override void OnTrigger(IGUIState guiState)
  30. {
  31. base.OnTrigger(guiState);
  32. if (onClick != null)
  33. onClick(guiState, hoveredControl);
  34. if (m_UseEvent)
  35. guiState.UseEvent();
  36. }
  37. protected override bool GetFinishContidtion(IGUIState guiState)
  38. {
  39. return true;
  40. }
  41. }
  42. }