/// <summary>
        /// Prepares the recording context.
        /// To start recording once you've called this method, you must call <see cref="StartRecording"/>.
        /// </summary>
        /// <remarks>
        /// Sets up the internal data for the recording session and pauses the simulation to ensure a proper synchronization between the Recorder and the Unity Editor.
        /// </remarks>
        public void PrepareRecording()
        {
            if (!Application.isPlaying)
            {
                throw new Exception("You can only call the PrepareRecording method in Play mode.");
            }

            if (RecorderOptions.VerboseMode)
            {
                Debug.Log("Prepare Recording.");
            }

            if (m_Settings == null)
            {
                throw new NullReferenceException("Can start recording without prefs");
            }

            SceneHook.PrepareSessionRoot();
            m_RecordingSessions = new List <RecordingSession>();

            foreach (var recorderSetting in m_Settings.RecorderSettings)
            {
                if (recorderSetting == null)
                {
                    if (RecorderOptions.VerboseMode)
                    {
                        Debug.Log("Ignoring unknown recorder.");
                    }

                    continue;
                }

                m_Settings.ApplyGlobalSetting(recorderSetting);

                if (recorderSetting.HasErrors())
                {
                    if (RecorderOptions.VerboseMode)
                    {
                        Debug.Log("Ignoring invalid recorder '" + recorderSetting.name + "'");
                    }

                    continue;
                }

                if (!recorderSetting.Enabled)
                {
                    if (RecorderOptions.VerboseMode)
                    {
                        Debug.Log("Ignoring disabled recorder '" + recorderSetting.name + "'");
                    }

                    continue;
                }

                var session = m_SceneHook.CreateRecorderSessionWithRecorderComponent(recorderSetting);

                m_RecordingSessions.Add(session);
            }
        }
Example #2
0
        /// <summary>
        /// Start recording. Works only in Playmode.
        /// </summary>
        /// <returns>false if an error occured. The console will usually contains logs about the errors.</returns>
        /// <exception cref="Exception">If not in Playmode.</exception>
        /// <exception cref="NullReferenceException">If settings is null.</exception>
        public bool StartRecording()
        {
            if (!Application.isPlaying)
            {
                throw new Exception("Start Recording can only be called in Playmode.");
            }

            if (m_Settings == null)
            {
                throw new NullReferenceException("Can start recording without prefs");
            }

            if (IsRecording())
            {
                if (Options.verboseMode)
                {
                    Debug.Log("Recording was already started.");
                }

                return(false);
            }

            if (Options.verboseMode)
            {
                Debug.Log("Start Recording.");
            }

            SceneHook.PrepareSessionRoot();

            m_RecordingSessions = new List <RecordingSession>();

            foreach (var recorderSetting in m_Settings.recorderSettings)
            {
                if (recorderSetting == null)
                {
                    if (Options.verboseMode)
                    {
                        Debug.Log("Ignoring unknown recorder.");
                    }

                    continue;
                }

                m_Settings.ApplyGlobalSetting(recorderSetting);

                if (recorderSetting.HasErrors())
                {
                    if (Options.verboseMode)
                    {
                        Debug.Log("Ignoring invalid recorder '" + recorderSetting.name + "'");
                    }

                    continue;
                }

                var errors = new List <string>();

                if (recorderSetting.ValidityCheck(errors))
                {
                    foreach (var error in errors)
                    {
                        Debug.LogWarning(recorderSetting.name + ": " + error);
                    }
                }

                if (errors.Count > 0)
                {
                    if (Options.verboseMode)
                    {
                        Debug.LogWarning("Recorder '" + recorderSetting.name +
                                         "' has warnings and may not record properly.");
                    }
                }

                if (!recorderSetting.enabled)
                {
                    if (Options.verboseMode)
                    {
                        Debug.Log("Ignoring disabled recorder '" + recorderSetting.name + "'");
                    }

                    continue;
                }

                var session = m_SceneHook.CreateRecorderSessionWithRecorderComponent(recorderSetting);

                m_RecordingSessions.Add(session);
            }

            var success = m_RecordingSessions.Any() && m_RecordingSessions.All(r => r.SessionCreated() && r.BeginRecording());

            return(success);
        }
        /// <summary>
        /// Prepares the recording context.
        /// To start recording once you've called this method, you must call <see cref="StartRecording"/>.
        /// </summary>
        /// <remarks>
        /// Sets up the internal data for the recording session and pauses the simulation to ensure a proper synchronization between the Recorder and the Unity Editor.
        /// </remarks>
        public void PrepareRecording()
        {
            if (!Application.isPlaying)
            {
                throw new Exception("You can only call the PrepareRecording method in Play mode.");
            }

            if (RecorderOptions.VerboseMode)
            {
                Debug.Log("Prepare Recording.");
            }

            if (m_Settings == null)
            {
                throw new NullReferenceException("Can start recording without prefs");
            }

            SceneHook.PrepareSessionRoot();
            m_RecordingSessions = new List <RecordingSession>();

            int numberOfSubframeRecorder = 0;
            int numberOfRecorderEnabled  = 0;

            foreach (var recorderSetting in m_Settings.RecorderSettings)
            {
                if (recorderSetting == null)
                {
                    if (RecorderOptions.VerboseMode)
                    {
                        Debug.Log("Ignoring unknown recorder.");
                    }

                    continue;
                }

                m_Settings.ApplyGlobalSetting(recorderSetting);

                if (recorderSetting.HasErrors())
                {
                    if (RecorderOptions.VerboseMode)
                    {
                        Debug.Log("Ignoring invalid recorder '" + recorderSetting.name + "'");
                    }

                    continue;
                }

                if (!recorderSetting.Enabled)
                {
                    if (RecorderOptions.VerboseMode)
                    {
                        Debug.Log("Ignoring disabled recorder '" + recorderSetting.name + "'");
                    }

                    continue;
                }

                if (recorderSetting.Enabled)
                {
                    numberOfRecorderEnabled++;
                }

                // Validate that only one recorder support enable capture SubFrames
                if (UnityHelpers.CaptureAccumulation(recorderSetting))
                {
                    numberOfSubframeRecorder++;

                    if (numberOfSubframeRecorder >= 1 && numberOfRecorderEnabled > 1)
                    {
                        Debug.LogError("You can only use one active Recorder at a time when you capture accumulation.");
                        continue;
                    }
                }

                var session = m_SceneHook.CreateRecorderSessionWithRecorderComponent(recorderSetting);

                m_RecordingSessions.Add(session);
            }
        }