ViveInput.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Valve.VR;
  5. public class ViveInput : MonoBehaviour
  6. {
  7. public PlayerReplay playerReplay;
  8. public BodySourceView bsv;
  9. private SteamVR_Action_Boolean grabPinch;
  10. private SteamVR_Action_Boolean grabGrib;
  11. private SteamVR_Action_Boolean teleport;
  12. private bool isRecording;
  13. private float recordingTime;
  14. private static bool isPlaying;
  15. public float csvTime;
  16. private void Start()
  17. {
  18. grabPinch = SteamVR_Actions.default_GrabPinch;
  19. grabGrib = SteamVR_Actions.default_GrabGrip;
  20. teleport = SteamVR_Actions.default_Teleport;
  21. }
  22. void Update()
  23. {
  24. if (grabPinch.GetStateDown(SteamVR_Input_Sources.Any) && !isPlaying)
  25. {
  26. Debug.Log("Loading...");
  27. csvTime = 0;
  28. isPlaying = true;
  29. StartCoroutine(playerReplay.Load());
  30. }
  31. if (teleport.GetStateDown(SteamVR_Input_Sources.Any))
  32. {
  33. //if (!isRecording)
  34. //{
  35. // Debug.Log("Recording...");
  36. // isRecording = true;
  37. //}
  38. //else
  39. //{
  40. // Debug.Log("Saving...");
  41. // isRecording = false;
  42. // recordingTime = 0;
  43. // playerReplay.Save();
  44. // playerReplay.ResetRecording();
  45. //}
  46. }
  47. if (grabGrib.GetStateDown(SteamVR_Input_Sources.Any))
  48. {
  49. }
  50. if (isRecording)
  51. {
  52. playerReplay.AddJoints(recordingTime);
  53. recordingTime += Time.deltaTime;
  54. }
  55. if (isPlaying)
  56. {
  57. csvTime += Time.deltaTime;
  58. }
  59. if (Input.GetKeyDown(KeyCode.J))
  60. {
  61. DebugData();
  62. }
  63. }
  64. public static IEnumerator WaitForControllerPress()
  65. {
  66. while (true)
  67. {
  68. if (SteamVR_Actions.default_GrabPinch.GetStateDown(SteamVR_Input_Sources.Any) || Input.GetKeyDown(KeyCode.Space))
  69. {
  70. break;
  71. }
  72. yield return null;
  73. }
  74. }
  75. public static void StopPlaying()
  76. {
  77. isPlaying = false;
  78. }
  79. private void DebugData()
  80. {
  81. string path = Application.dataPath + "/Recordings/OneArm_Backward.sav";
  82. JointsDataSequence data = SaveSystem.Load(path);
  83. for (int i = 0; i < data.recordingTimes.Count; i++)
  84. {
  85. Debug.Log(data.recordingTimes[i]);
  86. }
  87. Debug.Log("start: " + data.recordingTimes[0]);
  88. Debug.Log("end: " + data.recordingTimes[data.recordingTimes.Count - 1]);
  89. }
  90. }