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