ViveInput.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 SteamVR_Action_Vector2 trackpad;
  13. private bool isRecording;
  14. private float recordingTime;
  15. private static bool isPlaying;
  16. public float csvTime;
  17. private void Start()
  18. {
  19. grabPinch = SteamVR_Actions.default_GrabPinch;
  20. grabGrib = SteamVR_Actions.default_GrabGrip;
  21. teleport = SteamVR_Actions.default_Teleport;
  22. }
  23. void Update()
  24. {
  25. if (grabPinch.GetStateDown(SteamVR_Input_Sources.Any))
  26. {
  27. }
  28. if (teleport.GetStateDown(SteamVR_Input_Sources.Any))
  29. {
  30. if (!isRecording)
  31. {
  32. Debug.Log("Recording...");
  33. isRecording = true;
  34. }
  35. else
  36. {
  37. Debug.Log("Saving...");
  38. isRecording = false;
  39. recordingTime = 0;
  40. playerReplay.Save();
  41. playerReplay.ResetRecording();
  42. }
  43. }
  44. if (grabGrib.GetStateDown(SteamVR_Input_Sources.Any) && !isPlaying)
  45. {
  46. Debug.Log("Loading...");
  47. csvTime = 0;
  48. isPlaying = true;
  49. playerReplay.Load();
  50. }
  51. if (isRecording)
  52. {
  53. playerReplay.AddJoints(recordingTime);
  54. recordingTime += Time.deltaTime;
  55. }
  56. if (isPlaying)
  57. {
  58. csvTime += Time.deltaTime;
  59. }
  60. // TODO: Test haptic
  61. if (Input.GetKeyDown(KeyCode.Q))
  62. {
  63. SteamVR_Actions.default_Haptic[SteamVR_Input_Sources.LeftHand].Execute(0, 1, 10, 1);
  64. }
  65. if (Input.GetKeyDown(KeyCode.W))
  66. {
  67. SteamVR_Actions.default_Haptic[SteamVR_Input_Sources.RightHand].Execute(0, 1, 10, 1);
  68. }
  69. if (Input.GetKeyDown(KeyCode.E))
  70. {
  71. SteamVR_Actions.default_Haptic[SteamVR_Input_Sources.LeftFoot].Execute(0, 1, 10, 1);
  72. }
  73. if (Input.GetKeyDown(KeyCode.R))
  74. {
  75. SteamVR_Actions.default_Haptic[SteamVR_Input_Sources.RightFoot].Execute(0, 1, 10, 1);
  76. }
  77. }
  78. public static IEnumerator WaitForControllerPress()
  79. {
  80. while (true)
  81. {
  82. if (SteamVR_Actions.default_GrabPinch.GetStateDown(SteamVR_Input_Sources.Any) || Input.GetKeyDown(KeyCode.Space))
  83. {
  84. break;
  85. }
  86. yield return null;
  87. }
  88. }
  89. public static void StopPlaying()
  90. {
  91. isPlaying = false;
  92. }
  93. }