VRInput.cs 1.2 KB

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