TimelineWindow_TimeArea.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.Timeline
  4. {
  5. partial class TimelineWindow
  6. {
  7. [NonSerialized] TimelineTimeArea m_TimeArea;
  8. public TimeArea timeArea { get { return m_TimeArea; } }
  9. internal static class Styles
  10. {
  11. public static string DurationModeText = L10n.Tr("Duration Mode/{0}");
  12. }
  13. float m_LastFrameRate;
  14. bool m_TimeAreaDirty = true;
  15. void InitializeTimeArea()
  16. {
  17. if (m_TimeArea == null)
  18. {
  19. m_TimeArea = new TimelineTimeArea(state, false)
  20. {
  21. hRangeLocked = false,
  22. vRangeLocked = true,
  23. margin = 10,
  24. scaleWithWindow = true,
  25. hSlider = true,
  26. vSlider = false,
  27. hBaseRangeMin = 0.0f,
  28. hBaseRangeMax = WindowState.kMaxShownTime,
  29. hRangeMin = 0.0f,
  30. hScaleMax = WindowConstants.maxTimeAreaScaling,
  31. rect = state.timeAreaRect
  32. };
  33. m_TimeAreaDirty = true;
  34. InitTimeAreaFrameRate();
  35. SyncTimeAreaShownRange();
  36. }
  37. }
  38. void DrawTimelineRuler()
  39. {
  40. if (!currentMode.ShouldShowTimeArea(state))
  41. return;
  42. Rect rect = state.timeAreaRect;
  43. m_TimeArea.rect = new Rect(rect.x, rect.y, rect.width, clientArea.height - rect.y);
  44. if (m_LastFrameRate != state.referenceSequence.frameRate)
  45. InitTimeAreaFrameRate();
  46. SyncTimeAreaShownRange();
  47. m_TimeArea.BeginViewGUI();
  48. m_TimeArea.TimeRuler(rect, state.referenceSequence.frameRate, true, false, 1.0f, state.timeInFrames ? TimeArea.TimeFormat.Frame : TimeArea.TimeFormat.TimeFrame);
  49. m_TimeArea.EndViewGUI();
  50. }
  51. void InitTimeAreaFrameRate()
  52. {
  53. m_LastFrameRate = state.referenceSequence.frameRate;
  54. m_TimeArea.hTicks.SetTickModulosForFrameRate(m_LastFrameRate);
  55. }
  56. void SyncTimeAreaShownRange()
  57. {
  58. var range = state.timeAreaShownRange;
  59. if (!Mathf.Approximately(range.x, m_TimeArea.shownArea.x) || !Mathf.Approximately(range.y, m_TimeArea.shownArea.xMax))
  60. {
  61. // set view data onto the time area
  62. if (m_TimeAreaDirty)
  63. {
  64. m_TimeArea.SetShownHRange(range.x, range.y);
  65. m_TimeAreaDirty = false;
  66. }
  67. else
  68. {
  69. // set time area data onto the view data
  70. state.TimeAreaChanged();
  71. }
  72. }
  73. m_TimeArea.hBaseRangeMax = (float)state.editSequence.duration;
  74. }
  75. class TimelineTimeArea : TimeArea
  76. {
  77. readonly WindowState m_State;
  78. public TimelineTimeArea(WindowState state, bool minimalGUI) : base(minimalGUI)
  79. {
  80. m_State = state;
  81. }
  82. public override string FormatTickTime(float time, float frameRate, TimeFormat timeFormat)
  83. {
  84. time = m_State.timeReferenceMode == TimeReferenceMode.Global ?
  85. (float)m_State.editSequence.ToGlobalTime(time) : time;
  86. return FormatTime(time, frameRate, timeFormat);
  87. }
  88. }
  89. }
  90. }