暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Manipulator.cs 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. Event currentEvent = Event.current;
  21. var type = currentEvent.GetTypeForControl(m_Id);
  22. return HandleEvent(type, currentEvent, state);
  23. }
  24. public bool HandleEvent(EventType type, WindowState state)
  25. {
  26. Event currentEvent = Event.current;
  27. return HandleEvent(type, currentEvent, state);
  28. }
  29. bool HandleEvent(EventType type, Event evt, WindowState state)
  30. {
  31. if (m_Id == 0)
  32. m_Id = GUIUtility.GetPermanentControlID();
  33. bool isHandled = false;
  34. switch (type)
  35. {
  36. case EventType.ScrollWheel:
  37. isHandled = MouseWheel(evt, state);
  38. break;
  39. case EventType.MouseUp:
  40. {
  41. if (GUIUtility.hotControl == m_Id)
  42. {
  43. isHandled = MouseUp(evt, state);
  44. GUIUtility.hotControl = 0;
  45. evt.Use();
  46. }
  47. }
  48. break;
  49. case EventType.MouseDown:
  50. {
  51. isHandled = evt.clickCount < 2 ? MouseDown(evt, state) : DoubleClick(evt, state);
  52. if (isHandled)
  53. GUIUtility.hotControl = m_Id;
  54. }
  55. break;
  56. case EventType.MouseDrag:
  57. {
  58. if (GUIUtility.hotControl == m_Id)
  59. isHandled = MouseDrag(evt, state);
  60. }
  61. break;
  62. case EventType.KeyDown:
  63. isHandled = KeyDown(evt, state);
  64. break;
  65. case EventType.KeyUp:
  66. isHandled = KeyUp(evt, state);
  67. break;
  68. case EventType.ContextClick:
  69. isHandled = ContextClick(evt, state);
  70. break;
  71. case EventType.ValidateCommand:
  72. isHandled = ValidateCommand(evt, state);
  73. break;
  74. case EventType.ExecuteCommand:
  75. isHandled = ExecuteCommand(evt, state);
  76. break;
  77. }
  78. if (isHandled)
  79. evt.Use();
  80. return isHandled;
  81. }
  82. }
  83. }