ViveInput.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 void Start()
  16. {
  17. grabPinch = SteamVR_Actions.default_GrabPinch;
  18. grabGrib = SteamVR_Actions.default_GrabGrip;
  19. teleport = SteamVR_Actions.default_Teleport;
  20. }
  21. void Update()
  22. {
  23. if (grabPinch.GetStateDown(SteamVR_Input_Sources.Any))
  24. {
  25. }
  26. if (teleport.GetStateDown(SteamVR_Input_Sources.Any))
  27. {
  28. if (!isRecording)
  29. {
  30. Debug.Log("Recording...");
  31. isRecording = true;
  32. } else
  33. {
  34. Debug.Log("Saving...");
  35. isRecording = false;
  36. recordingTime = 0;
  37. playerReplay.Save();
  38. playerReplay.ResetRecording();
  39. }
  40. }
  41. if (grabGrib.GetStateDown(SteamVR_Input_Sources.Any))
  42. {
  43. Debug.Log("Loading...");
  44. playerReplay.Load();
  45. }
  46. if (isRecording)
  47. {
  48. playerReplay.AddJoints(recordingTime);
  49. recordingTime += Time.deltaTime;
  50. }
  51. }
  52. public static IEnumerator WaitForControllerPress()
  53. {
  54. bool done = false;
  55. while (!done)
  56. {
  57. if (SteamVR_Actions.default_GrabPinch.GetStateDown(SteamVR_Input_Sources.Any) || Input.GetKeyDown(KeyCode.Space))
  58. {
  59. done = true;
  60. }
  61. yield return null;
  62. }
  63. }
  64. }