説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

TimelinePlaybackControls.cs 7.3KB

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