Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

TimelineWindow_PlaybackControls.cs 3.4KB

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