public void Play(Recording recording, float startRecordingFromTime = 0) { currentRecording = recording; currentFrame = recording.GetClosestFrame(startRecordingFromTime); thisFrameInputs.Clear(); lastFrameInputs.Clear(); _mode = InputVCRMode.Playback; playbackTime = startRecordingFromTime; }
public void NewRecording() { // start recording live input currentRecording = new Recording(recordingFrameRate); currentFrame = 0; realRecordingTime = 0; nextPosSyncTime = -1f; nextPropertiesToRecord.Clear(); _mode = InputVCRMode.Record; }
public event System.Action finishedPlayback; // sent when playback finishes /// <summary> /// Start recording. Will append to already started recording /// </summary> public void Record() { if (currentRecording == null || currentRecording.recordingLength == 0) { NewRecording(); } else { _mode = InputVCRMode.Record; } }
public event System.Action finishedPlayback; // sent when playback finishes public void Record() { if (currentRecording == null || Mathf.Approximately(currentRecording.recordingLength, 0)) { NewRecording(); } else { _mode = InputVCRMode.Record; } }
/// <summary> /// Start playing back the current recording, if present. /// If currently paused, will just resume /// </summary> public void Play() { // if currently paused during playback, will continue if (mode == InputVCRMode.Pause) { _mode = InputVCRMode.Playback; } else { // if not given any input string, will use last recording Play(currentRecording); } }
/// <summary> /// Stop recording or playback and rewind Live input will be passed through /// </summary> public void Stop() { _mode = InputVCRMode.Passthru; currentFrame = 0; playbackTime = 0; }
/// <summary> /// Start recording. Will append to already started recording /// </summary> public void Record() { if ( currentRecording == null || currentRecording.recordingLength == 0 ) NewRecording(); else _mode = InputVCRMode.Record; }
/// <summary> /// Play the specified recording, from optional specified time /// </summary> /// <param name='recording'> /// Recording. /// </param> /// <param name='startRecordingFromTime'> /// OPTIONAL: Time to start recording at /// </param> public void Play( Recording recording, float startRecordingFromTime = 0 ) { currentRecording = new Recording( recording ); currentFrame = recording.GetClosestFrame ( startRecordingFromTime ); thisFrameInputs.Clear (); lastFrameInputs.Clear (); _mode = InputVCRMode.Playback; playbackTime = startRecordingFromTime; }
/// <summary> /// Start playing back the current recording, if present. /// If currently paused, will just resume /// </summary> public void Play() { // if currently paused during playback, will continue if ( mode == InputVCRMode.Pause ) _mode = InputVCRMode.Playback; else { // if not given any input string, will use last recording Play ( currentRecording ); } }
private IEnumerator WaitForXSeconds(float time) { yield return(new WaitForSeconds(time)); _mode = InputVCRMode.Playback; }
/// <summary> /// Starts a new recording. If old recording wasn't saved it will be lost forever! /// </summary> public void NewRecording() { // start recording live input currentRecording = new Recording( recordingFrameRate ); currentFrame = 0; realRecordingTime = 0; nextPosSyncTime = -1f; nextPropertiesToRecord.Clear (); _mode = InputVCRMode.Record; }
/// <summary> /// Start recording. Will append to already started recording /// </summary> public void Record() { if (currentRecording == null || currentRecording.recordingLength == 0) { NewRecording (); Debug.Log (currentRecording); } else { _mode = InputVCRMode.Record; Debug.Log (currentRecording); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); var recorder = (InputVCRRecorder)target; if (EditorApplication.isPlaying) { InputVCRMode recordMode = recorder.Mode; // record controls EditorGUILayout.LabelField("Controls", EditorStyles.boldLabel); // controls using (var playGroup = new EditorGUILayout.HorizontalScope()) { bool playEnabled = recordMode != InputVCRMode.Playback || recorder.IsPaused; GUI.enabled = playEnabled; if (GUILayout.Button("PLAY >", EditorStyles.miniButtonLeft)) { recorder.Play(); } bool pauseEnabled = recordMode != InputVCRMode.Passthru && !recorder.IsPaused; GUI.enabled = pauseEnabled; if (GUILayout.Button("PAUSE ||", EditorStyles.miniButtonMid)) { recorder.Pause(); } GUI.enabled = true; if (GUILayout.Button("REWIND <<", EditorStyles.miniButtonRight)) { recorder.RewindToStart(); } } using (var recordGroup = new EditorGUILayout.HorizontalScope()) { bool recordEnabled = recordMode != InputVCRMode.Record; GUI.enabled = recordEnabled; if (GUILayout.Button("RECORD O", EditorStyles.miniButtonLeft)) { recorder.Record(); } bool stopEnabled = recordMode != InputVCRMode.Passthru; GUI.enabled = stopEnabled; if (GUILayout.Button("STOP []", EditorStyles.miniButtonRight)) { recorder.Stop(); } } GUI.enabled = true; var currentRecording = recorder.CurrentRecording; if (recorder.Mode == InputVCRMode.Record) { EditorGUILayout.LabelField("Recording", EditorStyles.boldLabel); EditorGUILayout.LabelField("Length: " + recorder.CurrentPlaybackTime.ToString("f2")); } else { if (recorder.Mode == InputVCRMode.Playback) { EditorGUILayout.LabelField("Playing", EditorStyles.boldLabel); } else { EditorGUILayout.LabelField("Stopped", EditorStyles.boldLabel); } float time = recorder.CurrentPlaybackTime; float length = currentRecording.Length; EditorGUILayout.LabelField("Length: " + length.ToString("f2")); GUI.enabled = false; EditorGUILayout.Slider(time, 0, length, GUILayout.ExpandWidth(true)); GUI.enabled = true; } // recording save if (currentRecording != null) { if (GUILayout.Button("Save Recording")) { string recordingName = $"VCRRecord_{DateTime.Now:yy-MM-dd_HHmmss}"; string path = EditorUtility.SaveFilePanelInProject("Save Recording", recordingName, "txt", "Save current recording to disk as JSON"); if (!string.IsNullOrEmpty(path)) { string json = currentRecording.ToJson(); try { File.WriteAllText(path, json); AssetDatabase.Refresh(); } catch (Exception e) { Exception error = new Exception("Failed to write recording to disk", e); Debug.LogException(e); } } } } } // Recording load if (GUILayout.Button("Load Recording")) { string jsonPath = EditorUtility.OpenFilePanel("Load Recording", Application.dataPath, "txt"); if (!string.IsNullOrEmpty(jsonPath)) { try { string recordJson = File.ReadAllText(jsonPath); Recording r = new Recording(recordJson); recorder.LoadRecording(r); } catch (Exception e) { Exception error = new Exception("Failed to load recording from disk", e); Debug.LogException(e); } } } }
/// <summary> /// Pause recording or playback. All input will be blocked while paused /// </summary> public void Pause() { _mode = InputVCRMode.Pause; }
/// <summary> /// Pause recording or playback. All input will be blocked while paused /// </summary> public void Pause() { _mode = InputVCRMode.Pause; }
/// <summary> /// Stop recording or playback and rewind Live input will be passed through /// </summary> public void Stop() { _mode = InputVCRMode.Passthru; currentFrame = 0; playbackTime = 0; }
void LateUpdate() { if (_mode == InputVCRMode.Playback) { // update last frame and this frame // this way, all changes are transmitted, even if a button press lasts less than a frame (like in Input) lastFrameInputs = new Dictionary <string, InputInfo>(thisFrameInputs); int lastFrame = currentFrame; currentFrame = currentRecording.GetClosestFrame(playbackTime); if (currentFrame >= currentRecording.totalFrames) { imputRecorder.GetComponent <PlayButton>().SpawnCloneCopy(this.name, recordingNumber, 1, startPos, startRot); imputRecorder.GetComponent <PlayButton>().DestroyClone(this.gameObject); _mode = InputVCRMode.Pause; } else { if (firstLoopPlayback) { // float[] camRot = System.Array.ConvertAll(currentRecording.GetProperty(0, "camRot").Split(','), float.Parse); // this.GetComponent<CameraBehaviour>().SetRotationX(camRot[0]); // this.GetComponent<CameraBehaviour>().SetRotationZ(camRot[1]); this.gameObject.GetComponent <PlayerBehaviour>().transformToRotate.rotation = startRot; this.gameObject.GetComponent <PlayerBehaviour>().playerAnimator.rootRotation = startRot; this.transform.GetChild(1).transform.localRotation = startRot; this.transform.position = startPos; firstLoopPlayback = false; // currentFrame = 0; // playbackTime = 0; // thisFrameInputs.Clear(); // lastFrameInputs.Clear(); } else { // go through all changes in recorded input since last frame var changedInputs = new Dictionary <string, InputInfo>(); for (int frame = lastFrame + 1; frame <= currentFrame; frame++) { foreach (InputInfo input in currentRecording.GetInputs(frame)) { if (!thisFrameInputs.ContainsKey(input.inputName) || !thisFrameInputs[input.inputName].Equals(input)) { if (changedInputs.ContainsKey(input.inputName)) { changedInputs[input.inputName] = input; } else { changedInputs.Add(input.inputName, input); } } } // Updates the camera rotation try { if (playerObject != null) { if (playerObject.GetComponent <InputVCR>().recordMouseEvents == true) { float[] camRot = System.Array.ConvertAll(currentRecording.GetProperty(frame, "camRot").Split(','), float.Parse); //Debug.Log("This is Playback - X: " + camRot[0] + " Y: " + camRot[1]); this.GetComponent <CameraBehaviour>().SetRotationX(camRot[0]); this.GetComponent <CameraBehaviour>().SetRotationZ(camRot[1]); } } else { Debug.Log("No Player object found! Precise camera rotation not used!"); } } catch { Debug.Log("Try failed! Precise camera rotation not used!"); } // if (currentFrame == 0) // custom code more effective, but this is enough sometimes // { // string posString = currentRecording.GetProperty(0, "position"); // if (!string.IsNullOrEmpty(posString)) // transform.position = ParseVector3(posString); // string rotString = currentRecording.GetProperty(0, "rotation"); // if (!string.IsNullOrEmpty(rotString)) // transform.GetChild(1).transform.eulerAngles = ParseVector3(rotString); // } } // update input to be used this frame foreach (KeyValuePair <string, InputInfo> changedInput in changedInputs) { if (thisFrameInputs.ContainsKey(changedInput.Key)) { thisFrameInputs[changedInput.Key] = changedInput.Value; } else { thisFrameInputs.Add(changedInput.Key, changedInput.Value); } //Debug.Log("Input: " + changedInput.Key + ", ButtonState: " + changedInput.Value.ToString()); } playbackTime += Time.deltaTime; } } } else if (_mode == InputVCRMode.Record) { realRecordingTime += Time.deltaTime; // record current input to frames, until recording catches up with realtime while (currentTime < realRecordingTime) { if (currentRecording.totalFrames > (maxRecordTime * recordingFrameRate) * 2) { //currentRecording.RemoveOldestFrame(); //currentRecording.frames.RemoveRange(0, (int)(currentRecording.totalFrames - (maxRecordTime * recordingFrameRate))); //currentFrame = currentRecording.frames.Count; //realRecordingTime -= Time.deltaTime; //realRecordingTime -= (1000 - maxRecordTime); //Debug.Log("After: " + currentRecording.totalFrames); //Debug.Log("Current Frame: " + currentFrame); //Debug.Log("Recording Time: " + realRecordingTime); } //Debug.Log("Total Rec Frames: " + currentRecording.totalFrames); // This is the current recorded fram count. // Camera Rotation & Buttons if Required if (recordMouseEvents) { currentRecording.AddProperty(currentFrame, new FrameProperty("camRot", this.GetComponent <CameraBehaviour>().GetRotationX().ToString() + "," + this.GetComponent <CameraBehaviour>().GetRotationZ().ToString())); //currentRecording.AddProperty(currentFrame, new FrameProperty("position", Vector3ToString(transform.position))); //currentRecording.AddProperty(currentFrame, new FrameProperty("rotation", Vector3ToString(transform.GetChild(1).transform.eulerAngles))); //Debug.Log(currentRecording.GetProperty(currentFrame, "camRot")); //currentRecording.AddProperty(currentFrame, new FrameProperty("mousePos", Input.mousePosition.x.ToString() + "," + Input.mousePosition.y)); // for (int i = 0; i < 3; i++) // { // InputInfo mouseInput = new InputInfo(); // mouseInput.inputName = "mousebutton" + i; // mouseInput.isAxis = false; // mouseInput.mouseButtonNum = i; // currentRecording.AddInput(currentFrame, mouseInput); // } } // and buttons foreach (InputInfo input in inputsToRecord) { if (input.isAxis) { input.axisValue = hardInput.GetAxis(input.inputName, 1); } else { input.buttonState = hardInput.GetKey(input.inputName); } // else if (input.mouseButtonNum >= 0) // mouse buttons recorded above // { // input.buttonState = hardInput.GetKey(input.inputName); // } currentRecording.AddInput(currentFrame, input); } // synced location //SyncPosition(); // add position to properties // if (Time.time > nextPosSyncTime) // { // SyncPosition(); // add position to properties // nextPosSyncTime = Time.time + 1f / autoSyncLocationRate; // } // and any other properties foreach (FrameProperty prop in nextPropertiesToRecord) { currentRecording.AddProperty(currentFrame, prop); } nextPropertiesToRecord.Clear(); currentFrame++; //Debug.Log("Recording Current Frames: " + currentRecording.totalFrames); } } }