VRInput.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 ScrollRect scrollRect;
  11. // public Hand leftHand;
  12. // public Hand rightHand;
  13. // If more functions are added: a possibility to differentiate between a game mode and menu mode.
  14. // public GameObject Player;
  15. public GameObject CurrentMode;
  16. public InteractionManagement InteractionManagement;
  17. public bool inMenu => InteractionManagement.Instance.Menu_Opened;
  18. public bool isLocked => InteractionManagement.Instance.Robot_Locked;
  19. public Vector2 touchValue;
  20. private void Awake()
  21. {
  22. }
  23. // Start is called before the first frame update. At the beginning user is in menu and robot is locked.
  24. void Start()
  25. {
  26. if(CurrentMode != null && !CurrentMode.activeSelf){
  27. CurrentMode.SetActive(true);
  28. }
  29. }
  30. // Update is called once per frame
  31. void Update()
  32. {
  33. }
  34. // calculate the velocity and angle according to the mode
  35. public Vector2 getTouchValue()
  36. {
  37. touchValue = CurrentMode.GetComponent<IMode>().Signal;
  38. return CurrentMode.GetComponent<IMode>().Signal;
  39. }
  40. // Change the Mode, if not existed, change it to Default Mode
  41. public void SetMode(GameObject mode){
  42. if( this.CurrentMode != mode){
  43. this.CurrentMode.SetActive(false);
  44. mode.SetActive(true);
  45. this.CurrentMode = mode;
  46. }
  47. }
  48. }