A game about forced loneliness, made by TACStudios
1using System.Collections.Generic;
2using UnityEngine;
3
4namespace UnityEditor.Timeline
5{
6 internal interface ITimelinePlaybackControls
7 {
8 void Play();
9 void Pause();
10 void PreviousFrame();
11 void NextFrame();
12 void GoToFirstFrame();
13 void GoToLastFrame();
14 void SetCurrentTime(double time, TimelinePlaybackControls.Context context);
15 void SetCurrentFrame(int frame, TimelinePlaybackControls.Context context);
16 double GetCurrentTime(TimelinePlaybackControls.Context context);
17 int GetCurrentFrame(TimelinePlaybackControls.Context context);
18 }
19 /// <summary>
20 /// Use the TimelinePlaybackControls to manage the Timeline window's playback state, playhead location, and play range.
21 /// </summary>
22 public sealed class TimelinePlaybackControls
23 {
24 TimelineWindow.TimelinePlaybackControlsImpl m_Impl;
25
26 internal TimelinePlaybackControls(IWindowStateProvider stateProvider)
27 {
28 m_Impl = new TimelineWindow.TimelinePlaybackControlsImpl(stateProvider);
29 }
30
31 /// <summary>
32 /// Use Context to specify whether the time is based on local time or global time.
33 /// </summary>
34 public enum Context
35 {
36 /// <summary>
37 /// Time is relative to the current Timeline
38 /// </summary>
39 Local,
40 /// <summary>
41 /// Time is relative to the main Timeline
42 /// </summary>
43 Global
44 }
45
46 /// <summary>
47 /// Starts playback.
48 /// </summary>
49 /// <exception cref="System.InvalidOperationException">The Window associated with this instance has been destroyed.</exception>
50 public void Play() { m_Impl.Play(); }
51
52 /// <summary>
53 /// Pauses playback.
54 /// </summary>
55 /// <exception cref="System.InvalidOperationException">The Window associated with this instance has been destroyed.</exception>
56 public void Pause() { m_Impl.Pause(); }
57
58 /// <summary>
59 /// Moves the playhead to the previous frame.
60 /// </summary>
61 /// <exception cref="System.InvalidOperationException">The Window associated with this instance has been destroyed.</exception>
62 public void PreviousFrame() { m_Impl.PreviousFrame(); }
63
64 /// <summary>
65 /// Moves the playhead to the next frame.
66 /// </summary>
67 /// <exception cref="System.InvalidOperationException">The Window associated with this instance has been destroyed.</exception>
68 public void NextFrame() { m_Impl.NextFrame(); }
69
70 /// <summary>
71 /// Moves the playhead to the first frame.
72 /// </summary>
73 /// <exception cref="System.InvalidOperationException"> The Window associated with this instance has been destroyed.</exception>
74 public void GoToFirstFrame() { m_Impl.GoToFirstFrame(); }
75
76 /// <summary>
77 /// Moves the playhead to the last frame.
78 /// </summary>
79 /// <exception cref="System.InvalidOperationException"> The Window associated with this instance has been destroyed.</exception>
80 public void GoToLastFrame() { m_Impl.GoToLastFrame(); }
81
82 /// <summary>
83 /// Moves the playhead to a specific time.
84 /// </summary>
85 /// <param name="time">The time in seconds.</param>
86 /// <param name="context">
87 /// Use Context with a Sub-Timeline to specify whether the specified time is relative to the Sub-Timeline or the main Timeline.
88 /// If the Timeline is not a Sub-Timeline, the context uses local time regardless of the specified context.
89 /// </param>
90 /// Use <see cref="Context.Local"/>, the default, to move the playhead relative to the Sub-Timeline or Timeline.
91 /// Use <see cref="Context.Global"/> to move the playhead relative to the main Timeline.
92 /// <exception cref="System.InvalidOperationException">The Window associated with this instance has been destroyed.</exception>
93 /// <exception cref="System.ArgumentException">The context is invalid.</exception>
94 public void SetCurrentTime(double time, Context context = Context.Local) { m_Impl.SetCurrentTime(time, context); }
95
96 /// <summary>
97 /// Moves the playhead to a specific frame.
98 /// </summary>
99 /// <param name="frame">The frame to move to.</param>
100 /// <param name="context">
101 /// Use Context with a Sub-Timeline to specify whether the specified frame is relative to the Sub-Timeline or the main Timeline.
102 /// If the Timeline is not a Sub-Timeline, the context uses local time regardless of the specified context.
103 /// </param>
104 /// Use <see cref="Context.Local"/>, the default, to move the playhead relative to the Sub-Timeine.
105 /// Use <see cref="Context.Global"/> to move the playhead relative to the main Timeline.
106 /// <exception cref="System.InvalidOperationException">The Window associated with this instance has been destroyed.</exception>
107 /// <exception cref="System.ArgumentException">The context is invalid.</exception>
108 public void SetCurrentFrame(int frame, Context context = Context.Local) { m_Impl.SetCurrentFrame(frame, context); }
109
110 /// <summary>
111 /// Retrieves the location of the timeline playhead in seconds.
112 /// </summary>
113 /// <param name="context">
114 /// Use Context with a Sub-Timeline to specify whether the returned value is relative to the Sub-Timeline or the main Timeline.
115 /// If the Timeline is not a Sub-Timeline, the context uses local time regardless of the specified context.
116 /// </param>
117 /// Use <see cref="Context.Local"/>, the default, to retrieve the playhead location relative to the Sub-Timeline.
118 /// Use <see cref="Context.Global"/> to retrive the location relative to the main Timeline.
119 /// <exception cref="System.InvalidOperationException">The Window associated with this instance has been destroyed.</exception>
120 /// <exception cref="System.ArgumentException">The context is invalid.</exception>
121 /// <returns>The playhead location in seconds.</returns>
122 public double GetCurrentTime(Context context = Context.Local)
123 {
124 return m_Impl.GetCurrentTime(context);
125 }
126
127 /// <summary>
128 /// Retrieves the location of the timeline playhead in frames.
129 /// </summary>
130 /// <param name="context">
131 /// Use Context with a Sub-Timeline to specify whether the returned value is relative to the Sub-Timeline or the main Timeline.
132 /// If the Timeline is not a Sub-Timeline, the context uses local time regardless of the specified context.
133 /// </param>
134 /// Use <see cref="Context.Local"/>, the default, to retrieve the playhead location relative to the Sub-Timeline.
135 /// Use <see cref="Context.Global"/> to retrive the playhead location relative to the main Timeline.
136 /// <exception cref="System.InvalidOperationException">The Window associated with this instance has been destroyed.</exception>
137 /// <exception cref="System.ArgumentException">The context is invalid.</exception>
138 /// <returns>The playhead location in frames.</returns>
139 public int GetCurrentFrame(Context context = Context.Local)
140 {
141 return m_Impl.GetCurrentFrame(context);
142 }
143 }
144}