using System.Collections; using System.Collections.Generic; using UnityEngine; using Valve.VR; public class ViveInput : MonoBehaviour { public PlayerReplay playerReplay; public BodySourceView bsv; private SteamVR_Action_Boolean grabPinch; private SteamVR_Action_Boolean grabGrib; private SteamVR_Action_Boolean teleport; private bool isRecording; private float recordingTime; private static bool isPlaying; public float csvTime; private void Start() { grabPinch = SteamVR_Actions.default_GrabPinch; grabGrib = SteamVR_Actions.default_GrabGrip; teleport = SteamVR_Actions.default_Teleport; } void Update() { if (grabPinch.GetStateDown(SteamVR_Input_Sources.Any) && !isPlaying) { Debug.Log("Loading..."); csvTime = 0; isPlaying = true; StartCoroutine(playerReplay.Load()); } if (teleport.GetStateDown(SteamVR_Input_Sources.Any)) { //if (!isRecording) //{ // Debug.Log("Recording..."); // isRecording = true; //} //else //{ // Debug.Log("Saving..."); // isRecording = false; // recordingTime = 0; // playerReplay.Save(); // playerReplay.ResetRecording(); //} } if (grabGrib.GetStateDown(SteamVR_Input_Sources.Any)) { } if (isRecording) { playerReplay.AddJoints(recordingTime); recordingTime += Time.deltaTime; } if (isPlaying) { csvTime += Time.deltaTime; } if (Input.GetKeyDown(KeyCode.J)) { DebugData(); } } public static IEnumerator WaitForControllerPress() { while (true) { if (SteamVR_Actions.default_GrabPinch.GetStateDown(SteamVR_Input_Sources.Any) || Input.GetKeyDown(KeyCode.Space)) { break; } yield return null; } } public static void StopPlaying() { isPlaying = false; } private void DebugData() { string path = Application.dataPath + "/Recordings/OneArm_Backward.sav"; JointsDataSequence data = SaveSystem.Load(path); for (int i = 0; i < data.recordingTimes.Count; i++) { Debug.Log(data.recordingTimes[i]); } Debug.Log("start: " + data.recordingTimes[0]); Debug.Log("end: " + data.recordingTimes[data.recordingTimes.Count - 1]); } }