ViveInput.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. private SteamVR_Action_Boolean grabPinch;
  9. private SteamVR_Action_Boolean grabGrib;
  10. private SteamVR_Action_Boolean teleport;
  11. private bool isRecording;
  12. private float recordingTime;
  13. private void Start()
  14. {
  15. grabPinch = SteamVR_Actions.default_GrabPinch;
  16. grabGrib = SteamVR_Actions.default_GrabGrip;
  17. teleport = SteamVR_Actions.default_Teleport;
  18. }
  19. void Update()
  20. {
  21. if (grabPinch.GetStateDown(SteamVR_Input_Sources.Any))
  22. {
  23. Debug.Log("Recording...");
  24. isRecording = true;
  25. }
  26. if (teleport.GetStateDown(SteamVR_Input_Sources.Any))
  27. {
  28. Debug.Log("Saving...");
  29. isRecording = false;
  30. recordingTime = 0;
  31. playerReplay.Save();
  32. playerReplay.ResetRecording();
  33. }
  34. if (grabGrib.GetStateDown(SteamVR_Input_Sources.Any))
  35. {
  36. Debug.Log("Loading...");
  37. playerReplay.Load();
  38. }
  39. if (isRecording)
  40. {
  41. playerReplay.AddJoints(recordingTime);
  42. recordingTime += Time.deltaTime;
  43. }
  44. }
  45. }