public void StartPlaying() { StopRecording(); Replaying = true; PlayingIcon.enabled = true; StopIcon.enabled = false; inputField.interactable = false; CharacterMovement.Character.CanMove = true; _FrameNumber = 1; Debug.Log("Replaying Frame " + _FrameNumber); _CurrentFrame = Libcheckers.GetFrameStateObject(1); Vector3 newCharPos = new Vector3(float.Parse(_CurrentFrame.GetStateVariableValue("charPosX")), float.Parse(_CurrentFrame.GetStateVariableValue("charPosY")), float.Parse(_CurrentFrame.GetStateVariableValue("charPosZ"))); CharacterMovement.Character.SetPosition(newCharPos); Debug.Log(_CurrentFrame.ToString()); }
public void StartRecording() { StopPlaying(); inputField.interactable = false; Libcheckers.LoadGame("temp.db"); Recording = true; RecordingIcon.enabled = true; StopIcon.enabled = false; CharacterMovement.Character.CanMove = true; _FrameNumber = 1; Debug.Log("Recording Frame " + _FrameNumber); LibcheckersFrameState frame = new LibcheckersFrameState(_FrameNumber, new List <LibcheckersInput>(), new List <LibcheckersState>()); //frame.InsertInput(new LibcheckersInput("dummy", "1")); frame.InsertStateVariable(new LibcheckersState("deltaTime", ("" + Time.deltaTime))); frame.InsertStateVariable(new LibcheckersState("charPosX", "" + CharacterMovement.Character.CharPos.x)); frame.InsertStateVariable(new LibcheckersState("charPosY", "" + CharacterMovement.Character.CharPos.y)); frame.InsertStateVariable(new LibcheckersState("charPosZ", "" + CharacterMovement.Character.CharPos.z)); Libcheckers.InsertFrameState(frame); Debug.Log(frame.ToString()); }
// Update is called once per frame void Update() { if (Recording) { _FrameNumber++; Debug.Log("Recording Frame " + _FrameNumber); LibcheckersFrameState frame = new LibcheckersFrameState(_FrameNumber, new List <LibcheckersInput>(), new List <LibcheckersState>()); frame.InsertStateVariable(new LibcheckersState("deltaTime", ("" + Time.deltaTime))); if (KeysToListenTo != null) { foreach (KeyCode key in KeysToListenTo) { string name = System.Enum.GetName(typeof(KeyCode), key); LibcheckersInput input = null; if (Input.GetKeyDown(key)) { input = new LibcheckersInput(name, "d"); } else if (Input.GetKeyUp(key)) { input = new LibcheckersInput(name, "u"); } else if (Input.GetKey(key)) { input = new LibcheckersInput(name, "h"); } if (input != null) { frame.InsertInput(input); } } } if (ButtonsToListenTo != null) { foreach (string button in ButtonsToListenTo) { LibcheckersInput input = null; if (Input.GetButtonDown(button)) { input = new LibcheckersInput(button, "d"); } if (Input.GetButtonUp(button)) { input = new LibcheckersInput(button, "u"); } else if (Input.GetButton(button)) { input = new LibcheckersInput(button, "h"); } if (input != null) { frame.InsertInput(input); } } } if (AxesToListenTo != null) { foreach (string axis in AxesToListenTo) { float AxisValue = Input.GetAxisRaw(axis); if (AxisValue != 0) { frame.InsertInput(new LibcheckersInput(axis, "" + AxisValue)); } } } Libcheckers.InsertFrameState(frame); Debug.Log(frame.ToString()); } else if (Replaying) { _FrameNumber++; Debug.Log("Replaying Frame " + _FrameNumber); _CurrentFrame = Libcheckers.GetFrameStateObject(_FrameNumber); Debug.Log(_CurrentFrame.ToString()); if (_CurrentFrame.Empty || _CurrentFrame.GetStateVariableValue("endRec").Equals("1")) { StopPlaying(); Debug.Log("REPLAY OVER"); } else { _DeltaTime = float.Parse(_CurrentFrame.GetStateVariableValue("deltaTime")); } } }
public static void InsertFrameState(LibcheckersFrameState frameState) { InsertFrameState(frameState.ToString()); }