ViveInput.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. } else
  35. {
  36. Debug.Log("Saving...");
  37. isRecording = false;
  38. recordingTime = 0;
  39. playerReplay.Save();
  40. playerReplay.ResetRecording();
  41. }
  42. }
  43. if (grabGrib.GetStateDown(SteamVR_Input_Sources.Any) && !isPlaying)
  44. {
  45. Debug.Log("Loading...");
  46. csvTime = 0;
  47. isPlaying = true;
  48. playerReplay.Load();
  49. }
  50. if (isRecording)
  51. {
  52. playerReplay.AddJoints(recordingTime);
  53. recordingTime += Time.deltaTime;
  54. }
  55. if (isPlaying)
  56. {
  57. csvTime += Time.deltaTime;
  58. }
  59. }
  60. public static IEnumerator WaitForControllerPress()
  61. {
  62. while (true)
  63. {
  64. if (SteamVR_Actions.default_GrabPinch.GetStateDown(SteamVR_Input_Sources.Any) || Input.GetKeyDown(KeyCode.Space))
  65. {
  66. break;
  67. }
  68. yield return null;
  69. }
  70. }
  71. public static void StopPlaying()
  72. {
  73. isPlaying = false;
  74. }
  75. }