No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TimelineWindow_TimeCursor.cs 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Timeline;
  4. using UnityEngine.Playables;
  5. namespace UnityEditor.Timeline
  6. {
  7. partial class TimelineWindow
  8. {
  9. TimeAreaItem m_PlayHead;
  10. void TimeCursorGUI(TimelineItemArea area)
  11. {
  12. DrawTimeOnSlider();
  13. if (!CanDrawTimeCursor(area))
  14. return;
  15. if (m_PlayHead == null || m_PlayHead.style != styles.timeCursor)
  16. {
  17. m_PlayHead = new TimeAreaItem(styles.timeCursor, OnTrackHeadDrag);
  18. m_PlayHead.AddManipulator(new PlayheadContextMenu(m_PlayHead));
  19. }
  20. var headerMode = area == TimelineItemArea.Header;
  21. DrawTimeCursor(headerMode, !headerMode);
  22. }
  23. bool CanDrawTimeCursor(TimelineItemArea area)
  24. {
  25. if (!currentMode.ShouldShowTimeCursor(state))
  26. return false;
  27. if (treeView == null || state.editSequence.asset == null || (state.editSequence.asset != null && state.IsEditingAnEmptyTimeline()))
  28. return false;
  29. if (area == TimelineItemArea.Lines && !state.TimeIsInRange((float)state.editSequence.time))
  30. return false;
  31. return true;
  32. }
  33. void DrawTimeOnSlider()
  34. {
  35. if (currentMode.ShouldShowTimeCursor(state))
  36. {
  37. var colorDimFactor = EditorGUIUtility.isProSkin ? 0.7f : 0.9f;
  38. var c = styles.timeCursor.normal.textColor * colorDimFactor;
  39. float time = Mathf.Max((float)state.editSequence.time, 0);
  40. float duration = (float)state.editSequence.duration;
  41. m_TimeArea.DrawTimeOnSlider(time, c, duration, DirectorStyles.kDurationGuiThickness);
  42. }
  43. }
  44. void DrawTimeCursor(bool drawHead, bool drawline)
  45. {
  46. m_PlayHead.HandleManipulatorsEvents(state);
  47. if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
  48. {
  49. if (state.timeAreaRect.Contains(Event.current.mousePosition))
  50. {
  51. state.SetPlaying(false);
  52. m_PlayHead.HandleManipulatorsEvents(state);
  53. state.editSequence.time = Math.Max(0.0, state.GetSnappedTimeAtMousePosition(Event.current.mousePosition));
  54. }
  55. }
  56. m_PlayHead.drawLine = drawline;
  57. m_PlayHead.drawHead = drawHead;
  58. m_PlayHead.Draw(sequenceContentRect, state, state.editSequence.time);
  59. }
  60. void OnTrackHeadDrag(double newTime)
  61. {
  62. state.editSequence.time = Math.Max(0.0, newTime);
  63. m_PlayHead.showTooltip = true;
  64. }
  65. }
  66. }