/// <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); }
/// <summary> /// Build a new ActorPlaybackControl. /// </summary> /// <param name="representation">The actor meant to represent the subject during playback.</param> /// <param name="customEventHandler">Handles custom events that occurs to the subject in the recording.</param> /// <param name="recording">The recording containing this subject's recording and potentially others.</param> /// <param name="subjectRecording">The recording we will be acting out with the representaion provided.</param> public ActorPlaybackControl(GameObject representation, IPlaybackCustomEventHandler customEventHandler, Recording recording, SubjectRecording subjectRecording) { this.representation = representation; this.customEventHandler = customEventHandler; this.recording = recording; this.subjectRecording = subjectRecording; hasStartEvent = HasStartEvent(); lastTimeThroughPlayback = 0; lastPositionIndex = 0; }
public void OnCustomEvent(SubjectRecording subject, CustomEventCapture customEvent) { switch (customEvent.Name) { case "Box Destroyed": var dirtyCords = customEvent.Contents.Split(' '); Destroy(Instantiate(deathEffect, new Vector3(float.Parse(dirtyCords[0]), -10, float.Parse(dirtyCords[1])), Quaternion.Euler(-90, 0, 0)), 3f); break; case "Collision": var dirtyCollisionCords = customEvent.Contents.Split(' '); Destroy(Instantiate(collisionEffect, new Vector3(float.Parse(dirtyCollisionCords[0]), float.Parse(dirtyCollisionCords[1]), float.Parse(dirtyCollisionCords[2])), Quaternion.identity), 3f); break; default: Debug.LogWarningFormat("Don't know how to handle event type: {0}", customEvent.Name); break; } }
/// <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)); }
private static SubjectRecording[] FromTransport(Google.Protobuf.Collections.RepeatedField <Transport.SubjectRecording> transportRecordings) { if (transportRecordings == null) { throw new Exception("Nothing to convert (null recordings)"); } SubjectRecording[] recordings = new SubjectRecording[transportRecordings.Count]; for (int recordIndex = 0; recordIndex < transportRecordings.Count; recordIndex++) { recordings[recordIndex] = new SubjectRecording( transportRecordings[recordIndex].Id, transportRecordings[recordIndex].Name, new Dictionary <string, string>(transportRecordings[recordIndex].Metadata), FromTransport(transportRecordings[recordIndex].CapturedPositions), FromTransport(transportRecordings[recordIndex].CapturedRotations), FromTransport(transportRecordings[recordIndex].LifecycleEvents), FromTransport(transportRecordings[recordIndex].CustomEvents) ); } return(recordings); }