A game about forced loneliness, made by TACStudios
1using System;
2using System.Linq;
3using UnityEngine;
4using UnityEngine.Timeline;
5
6namespace UnityEditor.Timeline
7{
8 partial class TimelineWindow
9 {
10 /// <summary>
11 /// Internal class that implements TimelinePlaybackControls
12 /// </summary>
13 internal class TimelinePlaybackControlsImpl : ITimelinePlaybackControls
14 {
15 public TimelinePlaybackControlsImpl(IWindowStateProvider window)
16 {
17 if (window == null)
18 throw new ArgumentNullException(nameof(window),
19 "TimelineNavigator cannot be used with a null window");
20 m_Window = window;
21 }
22
23 public void Play()
24 {
25 windowState.SetPlaying(true);
26 }
27
28 public void Pause()
29 {
30 windowState.SetPlaying(false);
31 }
32
33 public void PreviousFrame()
34 {
35 windowState.editSequence.frame--;
36 }
37
38 public void NextFrame()
39 {
40 windowState.editSequence.frame++;
41 }
42
43 public void GoToFirstFrame()
44 {
45 windowState.editSequence.time = 0;
46 }
47
48 public void GoToLastFrame()
49 {
50 windowState.editSequence.time = windowState.editSequence.duration;
51 }
52
53 public void SetCurrentTime(double time, TimelinePlaybackControls.Context context)
54 {
55 ISequenceState targetSequenceState = GetTargetSequenceState(context);
56 targetSequenceState.time = time;
57 }
58
59 public void SetCurrentFrame(int frame, TimelinePlaybackControls.Context context)
60 {
61 ISequenceState targetSequenceState = GetTargetSequenceState(context);
62 targetSequenceState.frame = frame;
63 }
64
65 public double GetCurrentTime(TimelinePlaybackControls.Context context)
66 {
67 ISequenceState targetSequenceState = GetTargetSequenceState(context);
68 return targetSequenceState.time;
69 }
70
71 public int GetCurrentFrame(TimelinePlaybackControls.Context context)
72 {
73 ISequenceState targetSequenceState = GetTargetSequenceState(context);
74 return targetSequenceState.frame;
75 }
76
77 ISequenceState GetTargetSequenceState(TimelinePlaybackControls.Context context)
78 {
79 switch (context)
80 {
81 case TimelinePlaybackControls.Context.Global:
82 return windowState.masterSequence;
83 case TimelinePlaybackControls.Context.Local:
84 return windowState.editSequence;
85 default:
86 throw new ArgumentException("Unknown Context", nameof(context));
87 }
88 }
89
90 IWindowState windowState
91 {
92 get
93 {
94 if (m_Window == null || m_Window.windowState == null)
95 throw new InvalidOperationException("The Window associated to this instance has been destroyed");
96 return m_Window.windowState;
97 }
98 }
99
100 readonly IWindowStateProvider m_Window;
101 }
102
103 public override TimelinePlaybackControls playbackControls => new TimelinePlaybackControls(this);
104 }
105}