123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using UnityEditor.Recorder.Input;
- using UnityEngine.Playables;
- namespace UnityEditor.Recorder.Timeline
- {
- class RecorderPlayableBehaviour : PlayableBehaviour
- {
- PlayState m_PlayState = PlayState.Paused;
- public RecordingSession session { get; set; }
- WaitForEndOfFrameComponent endOfFrameComp;
- bool m_FirstOneSkipped;
- public override void OnGraphStart(Playable playable)
- {
- if (session != null)
- {
- // does not support multiple starts...
- session.SessionCreated();
- m_PlayState = PlayState.Paused;
- }
- }
- public override void OnGraphStop(Playable playable)
- {
- if (session != null && session.isRecording)
- {
- session.EndRecording();
- session.Dispose();
- session = null;
- }
- }
- public override void PrepareFrame(Playable playable, FrameData info)
- {
- if (session != null && session.isRecording)
- {
- session.PrepareNewFrame();
- }
- }
- public override void ProcessFrame(Playable playable, FrameData info, object playerData)
- {
- if (session != null)
- {
- if (endOfFrameComp == null)
- {
- endOfFrameComp = session.recorderGameObject.AddComponent<WaitForEndOfFrameComponent>();
- endOfFrameComp.m_playable = this;
- }
- }
- }
- public override void OnBehaviourPlay(Playable playable, FrameData info)
- {
- if (session == null)
- return;
- // Assumption: OnPlayStateChanged( PlayState.Playing ) ONLY EVER CALLED ONCE for this type of playable.
- m_PlayState = PlayState.Playing;
- session.BeginRecording();
- }
- public override void OnBehaviourPause(Playable playable, FrameData info)
- {
- if (session == null)
- return;
- if (session.isRecording && m_PlayState == PlayState.Playing)
- {
- session.EndRecording();
- session.Dispose();
- session = null;
- }
- m_PlayState = PlayState.Paused;
- }
- public void FrameEnded()
- {
- if (session != null && session.isRecording)
- session.RecordFrame();
- }
- }
- }
|