using System.Collections.Generic;
using UnityEngine;
namespace UnityEditor.Timeline
{
internal interface ITimelinePlaybackControls
{
void Play();
void Pause();
void PreviousFrame();
void NextFrame();
void GoToFirstFrame();
void GoToLastFrame();
void SetCurrentTime(double time, TimelinePlaybackControls.Context context);
void SetCurrentFrame(int frame, TimelinePlaybackControls.Context context);
double GetCurrentTime(TimelinePlaybackControls.Context context);
int GetCurrentFrame(TimelinePlaybackControls.Context context);
}
///
/// Use the TimelinePlaybackControls to manage the Timeline window's playback state, playhead location, and play range.
///
public sealed class TimelinePlaybackControls
{
TimelineWindow.TimelinePlaybackControlsImpl m_Impl;
internal TimelinePlaybackControls(IWindowStateProvider stateProvider)
{
m_Impl = new TimelineWindow.TimelinePlaybackControlsImpl(stateProvider);
}
///
/// Use Context to specify whether the time is based on local time or global time.
///
public enum Context
{
///
/// Time is relative to the current Timeline
///
Local,
///
/// Time is relative to the main Timeline
///
Global
}
///
/// Starts playback.
///
/// The Window associated with this instance has been destroyed.
public void Play() { m_Impl.Play(); }
///
/// Pauses playback.
///
/// The Window associated with this instance has been destroyed.
public void Pause() { m_Impl.Pause(); }
///
/// Moves the playhead to the previous frame.
///
/// The Window associated with this instance has been destroyed.
public void PreviousFrame() { m_Impl.PreviousFrame(); }
///
/// Moves the playhead to the next frame.
///
/// The Window associated with this instance has been destroyed.
public void NextFrame() { m_Impl.NextFrame(); }
///
/// Moves the playhead to the first frame.
///
/// The Window associated with this instance has been destroyed.
public void GoToFirstFrame() { m_Impl.GoToFirstFrame(); }
///
/// Moves the playhead to the last frame.
///
/// The Window associated with this instance has been destroyed.
public void GoToLastFrame() { m_Impl.GoToLastFrame(); }
///
/// Moves the playhead to a specific time.
///
/// The time in seconds.
///
/// Use Context with a Sub-Timeline to specify whether the specified time is relative to the Sub-Timeline or the main Timeline.
/// If the Timeline is not a Sub-Timeline, the context uses local time regardless of the specified context.
///
/// Use , the default, to move the playhead relative to the Sub-Timeline or Timeline.
/// Use to move the playhead relative to the main Timeline.
/// The Window associated with this instance has been destroyed.
/// The context is invalid.
public void SetCurrentTime(double time, Context context = Context.Local) { m_Impl.SetCurrentTime(time, context); }
///
/// Moves the playhead to a specific frame.
///
/// The frame to move to.
///
/// Use Context with a Sub-Timeline to specify whether the specified frame is relative to the Sub-Timeline or the main Timeline.
/// If the Timeline is not a Sub-Timeline, the context uses local time regardless of the specified context.
///
/// Use , the default, to move the playhead relative to the Sub-Timeine.
/// Use to move the playhead relative to the main Timeline.
/// The Window associated with this instance has been destroyed.
/// The context is invalid.
public void SetCurrentFrame(int frame, Context context = Context.Local) { m_Impl.SetCurrentFrame(frame, context); }
///
/// Retrieves the location of the timeline playhead in seconds.
///
///
/// Use Context with a Sub-Timeline to specify whether the returned value is relative to the Sub-Timeline or the main Timeline.
/// If the Timeline is not a Sub-Timeline, the context uses local time regardless of the specified context.
///
/// Use , the default, to retrieve the playhead location relative to the Sub-Timeline.
/// Use to retrive the location relative to the main Timeline.
/// The Window associated with this instance has been destroyed.
/// The context is invalid.
/// The playhead location in seconds.
public double GetCurrentTime(Context context = Context.Local)
{
return m_Impl.GetCurrentTime(context);
}
///
/// Retrieves the location of the timeline playhead in frames.
///
///
/// Use Context with a Sub-Timeline to specify whether the returned value is relative to the Sub-Timeline or the main Timeline.
/// If the Timeline is not a Sub-Timeline, the context uses local time regardless of the specified context.
///
/// Use , the default, to retrieve the playhead location relative to the Sub-Timeline.
/// Use to retrive the playhead location relative to the main Timeline.
/// The Window associated with this instance has been destroyed.
/// The context is invalid.
/// The playhead location in frames.
public int GetCurrentFrame(Context context = Context.Local)
{
return m_Impl.GetCurrentFrame(context);
}
}
}