Esempio n. 1
0
        /// <summary>
        /// Takes everything the recorder has seen so far and builds a recording from it, without stopping the recording process.
        /// </summary>
        /// <returns>A recording representing everything we've seen up until this point in time.</returns>
        /// <exception cref="System.InvalidOperationException">Thrown when the recorder is stopped.</exception>
        public Recording BuildRecording()
        {
            if (CurrentlyStopped())
            {
                throw new System.InvalidOperationException("Not recording anything! Nothing to build!");
            }

            if (CurrentlyPaused())
            {
                pauseSlices.Add(new Vector2(timePaused, Time.time));
            }

            var recordings = new SubjectRecording[subjectsToRecord.Count];

            for (int i = 0; i < recordings.Length; i++)
            {
                recordings[i] = subjectsToRecord[i].Save(timeStarted, Time.time, pauseSlices);
            }
            Recording recording = Recording.CreateInstance(recordings, CaptureUtil.FilterAndShift(customEvents, timeStarted, Time.time, pauseSlices), metadata);

            if (CurrentlyPaused())
            {
                pauseSlices.RemoveAt(pauseSlices.Count - 1);
            }
            return(recording);
        }
Esempio n. 2
0
        /// <summary>
        /// Converts protobuf recordings into a version that can be used for playback.
        /// </summary>
        /// <param name="transportRecordings">Protobuf recordings to be converted.</param>
        /// <returns>Recordings that can be used for things like playback.</returns>
        /// <exception cref="System.ArgumentException">Thrown when the recordings presented is null or empty.</exception>
        public static Recording[] FromTransport(params Transport.Recording[] transportRecordings)
        {
            if (transportRecordings == null)
            {
                throw new ArgumentException("Nothing to convert (null recordings)");
            }

            Recording[] recordings = new Recording[transportRecordings.Length];

            for (int recordIndex = 0; recordIndex < transportRecordings.Length; recordIndex++)
            {
                if (transportRecordings[recordIndex] == null)
                {
                    throw new ArgumentException(string.Format("Null transport Recording at index {0}.", recordIndex));
                }

                recordings[recordIndex] = Recording.CreateInstance(
                    FromTransport(transportRecordings[recordIndex].Subjects),
                    FromTransport(transportRecordings[recordIndex].CustomEvents),
                    new Dictionary <string, string>(transportRecordings[recordIndex].Metadata)
                    );
                recordings[recordIndex].RecordingName = transportRecordings[recordIndex].Name;
            }

            return(recordings);
        }
Esempio n. 3
0
        /// <summary>
        /// Stops the recorder and builds a recording for playback. Once a recorder is finished it is free to start making a whole new recording.
        /// </summary>
        /// <returns>A recording containing everything the recorder captured while not paused.</returns>
        /// <exception cref="System.InvalidOperationException">Thrown when the recorder is stopped.</exception>
        public Recording Finish()
        {
            if (CurrentlyStopped())
            {
                throw new System.InvalidOperationException("Not recording anything! Nothing to build!");
            }

            if (CurrentlyPaused())
            {
                Resume();
            }
            currentState = RecordingState.Stopped;
            var recordings = new SubjectRecording[subjectsToRecord.Count];

            for (int i = 0; i < recordings.Length; i++)
            {
                recordings[i] = subjectsToRecord[i].Save(timeStarted, Time.time, pauseSlices);
            }
            return(Recording.CreateInstance(recordings, CaptureUtil.FilterAndShift(customEvents, timeStarted, Time.time, pauseSlices), metadata));
        }