Manipulator.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using UnityEngine;
  2. namespace UnityEditor.Timeline
  3. {
  4. abstract class Manipulator
  5. {
  6. int m_Id;
  7. protected virtual bool MouseDown(Event evt, WindowState state) { return false; }
  8. protected virtual bool MouseDrag(Event evt, WindowState state) { return false; }
  9. protected virtual bool MouseWheel(Event evt, WindowState state) { return false; }
  10. protected virtual bool MouseUp(Event evt, WindowState state) { return false; }
  11. protected virtual bool DoubleClick(Event evt, WindowState state) { return false; }
  12. protected virtual bool KeyDown(Event evt, WindowState state) { return false; }
  13. protected virtual bool KeyUp(Event evt, WindowState state) { return false; }
  14. protected virtual bool ContextClick(Event evt, WindowState state) { return false; }
  15. protected virtual bool ValidateCommand(Event evt, WindowState state) { return false; }
  16. protected virtual bool ExecuteCommand(Event evt, WindowState state) { return false; }
  17. public virtual void Overlay(Event evt, WindowState state) {}
  18. public bool HandleEvent(WindowState state)
  19. {
  20. if (m_Id == 0)
  21. m_Id = GUIUtility.GetPermanentControlID();
  22. bool isHandled = false;
  23. var evt = Event.current;
  24. switch (evt.GetTypeForControl(m_Id))
  25. {
  26. case EventType.ScrollWheel:
  27. isHandled = MouseWheel(evt, state);
  28. break;
  29. case EventType.MouseUp:
  30. {
  31. if (GUIUtility.hotControl == m_Id)
  32. {
  33. isHandled = MouseUp(evt, state);
  34. GUIUtility.hotControl = 0;
  35. evt.Use();
  36. }
  37. }
  38. break;
  39. case EventType.MouseDown:
  40. {
  41. isHandled = evt.clickCount < 2 ? MouseDown(evt, state) : DoubleClick(evt, state);
  42. if (isHandled)
  43. GUIUtility.hotControl = m_Id;
  44. }
  45. break;
  46. case EventType.MouseDrag:
  47. {
  48. if (GUIUtility.hotControl == m_Id)
  49. isHandled = MouseDrag(evt, state);
  50. }
  51. break;
  52. case EventType.KeyDown:
  53. isHandled = KeyDown(evt, state);
  54. break;
  55. case EventType.KeyUp:
  56. isHandled = KeyUp(evt, state);
  57. break;
  58. case EventType.ContextClick:
  59. isHandled = ContextClick(evt, state);
  60. break;
  61. case EventType.ValidateCommand:
  62. isHandled = ValidateCommand(evt, state);
  63. break;
  64. case EventType.ExecuteCommand:
  65. isHandled = ExecuteCommand(evt, state);
  66. break;
  67. }
  68. if (isHandled)
  69. evt.Use();
  70. return isHandled;
  71. }
  72. }
  73. }