VideoSchedulerPlayableBehaviour.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Playables;
  5. namespace UnityEngine.Timeline
  6. {
  7. public sealed class VideoSchedulerPlayableBehaviour : PlayableBehaviour
  8. {
  9. private IEnumerable<TimelineClip> m_Clips;
  10. private PlayableDirector m_Director;
  11. internal PlayableDirector director
  12. {
  13. get { return m_Director; }
  14. set { m_Director = value; }
  15. }
  16. internal IEnumerable<TimelineClip> clips
  17. {
  18. get { return m_Clips; }
  19. set { m_Clips = value; }
  20. }
  21. public override void ProcessFrame(Playable playable, FrameData info, object playerData)
  22. {
  23. if (m_Clips == null)
  24. return;
  25. int inputPort = 0;
  26. foreach (TimelineClip clip in m_Clips)
  27. {
  28. ScriptPlayable<VideoPlayableBehaviour> scriptPlayable =
  29. (ScriptPlayable<VideoPlayableBehaviour>)playable.GetInput(inputPort);
  30. VideoPlayableBehaviour videoPlayableBehaviour = scriptPlayable.GetBehaviour();
  31. if (videoPlayableBehaviour != null)
  32. {
  33. double preloadTime = Math.Max(0.0, videoPlayableBehaviour.preloadTime);
  34. if (m_Director.time >= clip.start + clip.duration ||
  35. m_Director.time <= clip.start - preloadTime)
  36. videoPlayableBehaviour.StopVideo();
  37. else if (m_Director.time > clip.start - preloadTime)
  38. videoPlayableBehaviour.PrepareVideo();
  39. }
  40. ++inputPort;
  41. }
  42. }
  43. }
  44. }