ManipulationsTracks.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System.Linq;
  2. using UnityEngine;
  3. using UnityEngine.Timeline;
  4. namespace UnityEditor.Timeline
  5. {
  6. class InlineCurveResize : Manipulator
  7. {
  8. bool m_Captured;
  9. float m_CapturedHeight;
  10. float m_CaptureMouseYPos;
  11. InlineCurveResizeHandle m_Target;
  12. protected override bool MouseDown(Event evt, WindowState state)
  13. {
  14. m_Target = PickerUtils.PickedInlineCurveResizer();
  15. if (m_Target == null)
  16. return false;
  17. m_Captured = true;
  18. m_CapturedHeight = TimelineWindowViewPrefs.GetInlineCurveHeight(m_Target.trackGUI.track);
  19. m_CaptureMouseYPos = GUIUtility.GUIToScreenPoint(Event.current.mousePosition).y;
  20. state.AddCaptured(this);
  21. return true;
  22. }
  23. protected override bool MouseDrag(Event evt, WindowState state)
  24. {
  25. if (!m_Captured || m_Target == null)
  26. return false;
  27. var trackGUI = m_Target.trackGUI;
  28. float inlineTrackHeight = m_CapturedHeight +
  29. (GUIUtility.GUIToScreenPoint(Event.current.mousePosition).y - m_CaptureMouseYPos);
  30. TimelineWindowViewPrefs.SetInlineCurveHeight(trackGUI.track, Mathf.Max(inlineTrackHeight, 60.0f));
  31. state.GetWindow().treeView.CalculateRowRects();
  32. return true;
  33. }
  34. protected override bool MouseUp(Event evt, WindowState state)
  35. {
  36. if (!m_Captured)
  37. return false;
  38. state.RemoveCaptured(this);
  39. m_Captured = false;
  40. return true;
  41. }
  42. }
  43. class TrackDoubleClick : Manipulator
  44. {
  45. protected override bool DoubleClick(Event evt, WindowState state)
  46. {
  47. if (evt.button != 0)
  48. return false;
  49. var trackGUI = PickerUtils.PickedTrackBaseGUI();
  50. if (trackGUI == null)
  51. return false;
  52. // Double-click is only available for AnimationTracks: it conflicts with selection mechanics on other tracks
  53. if ((trackGUI.track as AnimationTrack) == null)
  54. return false;
  55. return EditTrackInAnimationWindow.Do(state, trackGUI.track);
  56. }
  57. }
  58. class TrackShortcutManipulator : Manipulator
  59. {
  60. protected override bool ExecuteCommand(Event evt, WindowState state)
  61. {
  62. if (state.IsCurrentEditingASequencerTextField())
  63. return false;
  64. var tracks = SelectionManager.SelectedTracks().ToList();
  65. var itemGUIs = SelectionManager.SelectedClipGUI();
  66. foreach (var itemGUI in itemGUIs)
  67. {
  68. var trackGUI = itemGUI.parent == null ? null : itemGUI.parent as TimelineTrackBaseGUI;
  69. if (trackGUI == null)
  70. continue;
  71. if (!tracks.Contains(trackGUI.track))
  72. tracks.Add(trackGUI.track);
  73. }
  74. return TrackAction.HandleShortcut(state, evt, tracks.ToArray());
  75. }
  76. }
  77. }