A game about forced loneliness, made by TACStudios
1using System;
2using System.Linq;
3using UnityEngine;
4
5namespace UnityEditor.Timeline
6{
7 partial class TimelineWindow
8 {
9 TimeAreaItem m_PlayRangeEnd;
10 TimeAreaItem m_PlayRangeStart;
11
12 void PlayRangeGUI(TimelineItemArea area)
13 {
14 if (!currentMode.ShouldShowPlayRange(state) || treeView == null)
15 return;
16
17 if (state.masterSequence.asset != null && !state.masterSequence.asset.GetRootTracks().Any())
18 return;
19
20 // left Time Cursor
21 if (m_PlayRangeStart == null || m_PlayRangeStart.style != styles.playTimeRangeStart)
22 {
23 m_PlayRangeStart = new TimeAreaItem(styles.playTimeRangeStart, OnTrackHeadMinSelectDrag);
24 Vector2 offset = new Vector2(-2.0f, 0);
25 m_PlayRangeStart.boundOffset = offset;
26 }
27
28 // right Time Cursor
29 if (m_PlayRangeEnd == null || m_PlayRangeEnd.style != styles.playTimeRangeEnd)
30 {
31 m_PlayRangeEnd = new TimeAreaItem(styles.playTimeRangeEnd, OnTrackHeadMaxSelectDrag);
32 Vector2 offset = new Vector2(2.0f, 0);
33 m_PlayRangeEnd.boundOffset = offset;
34 }
35
36 if (area == TimelineItemArea.Header)
37 DrawPlayRange(true, false);
38 else if (area == TimelineItemArea.Lines)
39 DrawPlayRange(false, true);
40 }
41
42 void DrawPlayRange(bool drawHeads, bool drawLines)
43 {
44 Rect timeCursorRect = state.timeAreaRect;
45 timeCursorRect.height = clientArea.height;
46
47 m_PlayRangeEnd.HandleManipulatorsEvents(state);
48 m_PlayRangeStart.HandleManipulatorsEvents(state);
49
50 // The first time a user enable the play range, we put the play range 75% around the current time...
51 if (state.playRange == TimelineAssetViewModel.NoPlayRangeSet)
52 {
53 double minimumPlayRangeTime = 0.01;
54 double t0 = Math.Max(0.0f, state.PixelToTime(state.timeAreaRect.xMin));
55 double t1 = Math.Min(state.masterSequence.duration, state.PixelToTime(state.timeAreaRect.xMax));
56
57 if (Math.Abs(t1 - t0) <= minimumPlayRangeTime)
58 {
59 state.playRange = new PlayRange(t0, t1);
60 return;
61 }
62
63 double deltaT = (t1 - t0) * 0.25 / 2.0;
64
65 t0 += deltaT;
66 t1 -= deltaT;
67
68 if (t1 < t0)
69 {
70 double temp = t0;
71 t0 = t1;
72 t1 = temp;
73 }
74
75 if (Math.Abs(t1 - t0) < minimumPlayRangeTime)
76 {
77 if (t0 - minimumPlayRangeTime > 0.0f)
78 t0 -= minimumPlayRangeTime;
79 else if (t1 + minimumPlayRangeTime < state.masterSequence.duration)
80 t1 += minimumPlayRangeTime;
81 }
82
83 state.playRange = new PlayRange(t0, t1);
84 }
85
86 // Draw the head or the lines according to the parameters..
87 m_PlayRangeStart.drawHead = drawHeads;
88 m_PlayRangeStart.drawLine = drawLines;
89
90 m_PlayRangeEnd.drawHead = drawHeads;
91 m_PlayRangeEnd.drawLine = drawLines;
92
93 var playRangeTime = state.playRange;
94 m_PlayRangeStart.Draw(sequenceContentRect, state, playRangeTime.start);
95 m_PlayRangeEnd.Draw(sequenceContentRect, state, playRangeTime.end);
96
97 // Draw Time Range Box from Start to End...
98 if (state.playRangeEnabled && m_PlayHead != null)
99 {
100 Rect rect =
101 Rect.MinMaxRect(
102 Mathf.Clamp(state.TimeToPixel(playRangeTime.start), state.timeAreaRect.xMin, state.timeAreaRect.xMax),
103 m_PlayHead.bounds.yMax,
104 Mathf.Clamp(state.TimeToPixel(playRangeTime.end), state.timeAreaRect.xMin, state.timeAreaRect.xMax),
105 sequenceContentRect.height + state.timeAreaRect.height + timeCursorRect.y
106 );
107
108
109 EditorGUI.DrawRect(rect, DirectorStyles.Instance.customSkin.colorRange);
110
111 rect.height = 3f;
112 EditorGUI.DrawRect(rect, Color.white);
113 }
114 }
115
116 void OnTrackHeadMinSelectDrag(double newTime)
117 {
118 PlayRange range = state.playRange;
119 range.start = newTime;
120 state.playRange = range;
121 m_PlayRangeStart.showTooltip = true;
122 }
123
124 void OnTrackHeadMaxSelectDrag(double newTime)
125 {
126 PlayRange range = state.playRange;
127 range.end = newTime;
128 state.playRange = range;
129 m_PlayRangeEnd.showTooltip = true;
130 }
131 }
132}