A game about forced loneliness, made by TACStudios
1using System;
2using UnityEngine;
3using UnityEngine.Timeline;
4
5namespace UnityEditor.Timeline
6{
7 partial class TimelineWindow
8 {
9 TimeAreaItem m_TimelineDuration;
10
11 void DurationGUI(TimelineItemArea area, double duration)
12 {
13 // don't show the duration if the time area is not visible for some other reason.
14 if (!currentMode.ShouldShowTimeArea(state))
15 return;
16
17 bool headerMode = area == TimelineItemArea.Header;
18
19 if (state.IsEditingASubTimeline())
20 {
21 if (headerMode)
22 HighlightTimeAreaRange(state.editSequence.GetEvaluableRange(), DirectorStyles.Instance.customSkin.colorSubSequenceDurationLine);
23
24 return;
25 }
26
27 // don't show the duration if there's none.
28 if (state.editSequence.asset.durationMode == TimelineAsset.DurationMode.BasedOnClips && duration <= 0.0f)
29 return;
30
31 if (m_TimelineDuration == null || m_TimelineDuration.style != styles.endmarker)
32 {
33 m_TimelineDuration = new TimeAreaItem(styles.endmarker, OnTrackDurationDrag)
34 {
35 tooltip = L10n.Tr("End of sequence marker"),
36 boundOffset = new Vector2(0.0f, -DirectorStyles.kDurationGuiThickness)
37 };
38 }
39
40 DrawDuration(headerMode, !headerMode, duration);
41 }
42
43 void DrawDuration(bool drawhead, bool drawline, double duration)
44 {
45 if (state.TimeIsInRange((float)duration))
46 {
47 // Set the colors based on the mode
48 Color lineColor = DirectorStyles.Instance.customSkin.colorEndmarker;
49 Color headColor = Color.white;
50
51 bool canMoveHead = !EditorApplication.isPlaying && state.editSequence.asset.durationMode == TimelineAsset.DurationMode.FixedLength;
52
53 if (canMoveHead)
54 {
55 if (Event.current.type == EventType.MouseDown)
56 {
57 if (m_TimelineDuration.bounds.Contains(Event.current.mousePosition))
58 {
59 if (m_PlayHead != null && m_PlayHead.bounds.Contains(Event.current.mousePosition))
60 {
61 // ignore duration markers if the mouse is over the TimeCursor.
62 canMoveHead = false;
63 }
64 }
65 }
66 }
67 else
68 {
69 lineColor.a *= 0.66f;
70 headColor = DirectorStyles.Instance.customSkin.colorDuration;
71 }
72
73 if (canMoveHead)
74 m_TimelineDuration.HandleManipulatorsEvents(state);
75
76 m_TimelineDuration.lineColor = lineColor;
77 m_TimelineDuration.headColor = headColor;
78 m_TimelineDuration.drawHead = drawhead;
79 m_TimelineDuration.drawLine = drawline;
80 m_TimelineDuration.canMoveHead = canMoveHead;
81
82 // Draw the TimeAreaItem
83 // Rect trackheadRect = treeviewBounds;
84 //trackheadRect.height = clientArea.height;
85 m_TimelineDuration.Draw(sequenceContentRect, state, duration);
86 }
87
88 // Draw Blue line in timeline indicating the duration...
89 if (state.editSequence.asset != null && drawhead)
90 {
91 HighlightTimeAreaRange(state.editSequence.GetEvaluableRange(), DirectorStyles.Instance.customSkin.colorDurationLine);
92 }
93 }
94
95 void HighlightTimeAreaRange(Range range, Color lineColor)
96 {
97 if (range.length <= 0.0 || !state.RangeIsVisible(range)) return;
98
99 Rect lineRect = Rect.MinMaxRect(
100 Math.Max(state.TimeToPixel(range.start), state.timeAreaRect.xMin),
101 state.timeAreaRect.y - DirectorStyles.kDurationGuiThickness + state.timeAreaRect.height,
102 Math.Min(state.TimeToPixel(range.end), state.timeAreaRect.xMax),
103 state.timeAreaRect.y + state.timeAreaRect.height);
104 EditorGUI.DrawRect(lineRect, lineColor);
105 }
106
107 // Drag handler for the gui
108 void OnTrackDurationDrag(double newTime)
109 {
110 if (state.editSequence.asset.durationMode == TimelineAsset.DurationMode.FixedLength && !state.editSequence.isReadOnly)
111 {
112 // this is the first call to the drag
113 if (m_TimelineDuration.firstDrag)
114 {
115 UndoExtensions.RegisterTimeline(state.editSequence.asset, L10n.Tr("Change Duration"));
116 }
117
118 state.editSequence.asset.fixedDuration = newTime;
119
120 // when setting a new length, modify the duration of the timeline playable directly instead of
121 // rebuilding the whole graph
122 state.UpdateRootPlayableDuration(newTime);
123 }
124
125 m_TimelineDuration.showTooltip = true;
126 }
127 }
128}