VRInput.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using UnityEngine;
  2. using System.Collections;
  3. using Valve.VR;
  4. using UnityEngine.UI;
  5. using Valve.VR.InteractionSystem;
  6. // Class that handles controller input.
  7. // Attached to GameObject Input in the hierachy.
  8. public class VRInput : MonoBehaviour
  9. {
  10. public GameObject CurrentMode;
  11. public bool inMenu => InteractionManagement.Instance.Menu_Opened;
  12. public bool isLocked => InteractionManagement.Instance.Robot_Locked;
  13. public Vector2 touchValue;
  14. private void Awake()
  15. {
  16. }
  17. // Start is called before the first frame update. At the beginning user is in menu and robot is locked.
  18. void Start()
  19. {
  20. if(CurrentMode != null && !CurrentMode.activeSelf){
  21. CurrentMode.SetActive(true);
  22. }
  23. }
  24. // Update is called once per frame
  25. void Update()
  26. {
  27. }
  28. // update the velocity and angle according to the mode
  29. public Vector2 getTouchValue()
  30. {
  31. Vector2 signal = Vector2.zero;
  32. if(CurrentMode!=null){
  33. signal = CurrentMode.GetComponent<IMode>().Signal;
  34. }
  35. touchValue = signal;
  36. return signal;
  37. }
  38. // Change the Mode so that it can get its signal
  39. public void SetMode(GameObject mode){
  40. if( this.CurrentMode != mode){
  41. if(this.CurrentMode != null){
  42. this.CurrentMode.SetActive(false);
  43. }
  44. mode.SetActive(true);
  45. this.CurrentMode = mode;
  46. }
  47. }
  48. }