A game about forced loneliness, made by TACStudios
1using UnityEngine;
2
3namespace UnityEditor.Timeline
4{
5 /// <summary>
6 /// Scrolling mode during playback for the timeline window.
7 /// </summary>
8 public enum PlaybackScrollMode
9 {
10 /// <summary>
11 /// Timeline window doesn't change while the playhead is leaving the window.
12 /// </summary>
13 None,
14 /// <summary>
15 /// Timeline window pans its content when the playhead arrive at the right of the window (like a paging scrolling).
16 /// </summary>
17 Pan,
18 /// <summary>
19 /// Timeline window move the content as the playhead moves.
20 /// When the playhead reach the middle of the window, it stays there and the content scroll behind it.
21 /// </summary>
22 Smooth
23 }
24
25 static class PlaybackScroller
26 {
27 public static void AutoScroll(WindowState state)
28 {
29 if (Event.current.type != EventType.Layout)
30 return;
31
32 switch (state.autoScrollMode)
33 {
34 case PlaybackScrollMode.Pan:
35 DoPanScroll(state);
36 break;
37 case PlaybackScrollMode.Smooth:
38 DoSmoothScroll(state);
39 break;
40 }
41 }
42
43 static void DoSmoothScroll(WindowState state)
44 {
45 if (state.playing)
46 state.SetPlayHeadToMiddle();
47
48 state.UpdateLastFrameTime();
49 }
50
51 static void DoPanScroll(WindowState state)
52 {
53 if (!state.playing)
54 return;
55
56 var paddingDeltaTime = state.PixelDeltaToDeltaTime(WindowConstants.autoPanPaddingInPixels);
57 var showRange = state.timeAreaShownRange;
58 var rightBoundForPan = showRange.y - paddingDeltaTime;
59 if (state.editSequence.time > rightBoundForPan)
60 {
61 var leftBoundForPan = showRange.x + paddingDeltaTime;
62 var delta = rightBoundForPan - leftBoundForPan;
63 state.SetTimeAreaShownRange(showRange.x + delta, showRange.y + delta);
64 }
65 }
66 }
67}