Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
950 B

  1. namespace Oculus.Platform.Samples.VrHoops
  2. {
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. // Helper class to attach to the main camera that raycasts where the
  6. // user is looking to select/deselect Buttons.
  7. public class VREyeRaycaster : MonoBehaviour
  8. {
  9. [SerializeField] private UnityEngine.EventSystems.EventSystem m_eventSystem = null;
  10. private Button m_currentButton;
  11. void Update ()
  12. {
  13. RaycastHit hit;
  14. Button button = null;
  15. // do a forward raycast to see if we hit a Button
  16. if (Physics.Raycast(transform.position, transform.forward, out hit, 50f))
  17. {
  18. button = hit.collider.GetComponent<Button>();
  19. }
  20. if (button != null)
  21. {
  22. if (m_currentButton != button)
  23. {
  24. m_currentButton = button;
  25. m_currentButton.Select();
  26. }
  27. }
  28. else if (m_currentButton != null)
  29. {
  30. m_currentButton = null;
  31. if (m_eventSystem != null)
  32. {
  33. m_eventSystem.SetSelectedGameObject(null);
  34. }
  35. }
  36. }
  37. }
  38. }