ViveInput.cs 3.6 KB

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