No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VideoSchedulerPlayableBehaviour.cs 1.6KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Playables;
  4. namespace Timeline.Samples
  5. {
  6. // The runtime instance of the VideoTrack. It is responsible for letting the VideoPlayableBehaviours
  7. // they need to start loading the video
  8. public sealed class VideoSchedulerPlayableBehaviour : PlayableBehaviour
  9. {
  10. // Called every frame that the timeline is evaluated. This is called prior to
  11. // PrepareFrame on any of its input playables.
  12. public override void PrepareFrame(Playable playable, FrameData info)
  13. {
  14. // Searches for clips that are in the 'preload' area and prepares them for playback
  15. var timelineTime = playable.GetGraph().GetRootPlayable(0).GetTime();
  16. for (int i = 0; i < playable.GetInputCount(); i++)
  17. {
  18. if (playable.GetInput(i).GetPlayableType() != typeof(VideoPlayableBehaviour))
  19. continue;
  20. if (playable.GetInputWeight(i) <= 0.0f)
  21. {
  22. ScriptPlayable<VideoPlayableBehaviour> scriptPlayable = (ScriptPlayable<VideoPlayableBehaviour>)playable.GetInput(i);
  23. VideoPlayableBehaviour videoPlayableBehaviour = scriptPlayable.GetBehaviour();
  24. double preloadTime = Math.Max(0.0, videoPlayableBehaviour.preloadTime);
  25. double clipStart = videoPlayableBehaviour.startTime;
  26. if (timelineTime > clipStart - preloadTime && timelineTime <= clipStart)
  27. videoPlayableBehaviour.PrepareVideo();
  28. }
  29. }
  30. }
  31. }
  32. }