Jog.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using UnityEditor.ShortcutManagement;
  2. using UnityEngine;
  3. using UnityEngine.Timeline;
  4. namespace UnityEditor.Timeline
  5. {
  6. class Jog : Manipulator
  7. {
  8. Vector2 m_MouseDownOrigin = Vector2.zero;
  9. [ClutchShortcut("Timeline/Jog", typeof(TimelineWindow), KeyCode.J)]
  10. static void JogShortcut(ShortcutArguments args)
  11. {
  12. if (args.stage == ShortcutStage.Begin)
  13. {
  14. (args.context as TimelineWindow).state.isJogging = true;
  15. }
  16. else if (args.stage == ShortcutStage.End)
  17. {
  18. (args.context as TimelineWindow).state.isJogging = false;
  19. }
  20. }
  21. protected override bool MouseDown(Event evt, WindowState state)
  22. {
  23. if (!state.isJogging)
  24. return false;
  25. m_MouseDownOrigin = evt.mousePosition;
  26. state.playbackSpeed = 0.0f;
  27. state.Play();
  28. return true;
  29. }
  30. protected override bool MouseUp(Event evt, WindowState state)
  31. {
  32. if (!state.isJogging)
  33. {
  34. return false;
  35. }
  36. m_MouseDownOrigin = evt.mousePosition;
  37. state.playbackSpeed = 0.0f;
  38. state.Play();
  39. return false;
  40. }
  41. protected override bool MouseDrag(Event evt, WindowState state)
  42. {
  43. if (!state.isJogging)
  44. return false;
  45. var distance = evt.mousePosition - m_MouseDownOrigin;
  46. state.playbackSpeed = distance.x * 0.002f;
  47. state.Play();
  48. return true;
  49. }
  50. }
  51. }