SceneHandler.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* SceneHandler.cs
  2. * author: Lydia Ebbinghaus
  3. */
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using System;
  7. // Class that handles interactions made with a modified SteamVR laser pointer.
  8. // Attached to GameObject Camera Scroll Menu (> LeftHand > SteamVRObjects > Player) in the hierachy.
  9. public class SceneHandler : MonoBehaviour
  10. {
  11. public SteamVR_LaserPointerMod laserPointer;
  12. public ScrollRect scrollRect;
  13. private PointerEventArgs klicked;
  14. // Just for tesing.
  15. public bool klick;
  16. void Awake()
  17. {
  18. laserPointer.PointerIn += PointerInside;
  19. laserPointer.PointerOut += PointerOutside;
  20. laserPointer.PointerClick += PointerClick;
  21. // Experimental: Enable to change realization of scrolling to : scrolling with laser pointer.
  22. // Needs to be improved. If enabled, disable scrolling in VRInput.
  23. //laserPointer.PointerDown += PointerScrollDown;
  24. //laserPointer.PointerUp += PointerScrollUp;
  25. }
  26. // If a pointerklick event was triggered and target was a button. Activate buttons script.
  27. // In this case call ActivateDeactivateCamera.
  28. public void PointerClick(object sender, PointerEventArgs e)
  29. {
  30. try
  31. {
  32. // !Test
  33. //e.target.GetComponent<Button>().onClick.Invoke();
  34. e.target.GetComponent<Button>().ButtonDown.Invoke();
  35. klicked =e;
  36. klick = true;
  37. }
  38. catch(NullReferenceException)
  39. {
  40. klick = false;
  41. Debug.Log("SceneHandler.cs: No camera to choose.");
  42. }
  43. }
  44. // Actual scrolling in script : VRInput, just Experimental.
  45. // Needs to be modified if scrolling should be realized with laser pointer or any other way than a button.
  46. // Scroll up in menu.
  47. public void PointerScrollUp(object sender, PointerEventArgs e)
  48. {
  49. if(scrollRect.verticalNormalizedPosition <=0.9f)
  50. {
  51. scrollRect.verticalNormalizedPosition+=0.1f;
  52. Debug.Log("SceneHandler.cs: Scroll up "+ e.target.name);
  53. }
  54. }
  55. // Actual scrolling in script : VRInput, just Experimental.
  56. // Needs to be modified if scrolling should be realized with laser pointer or any other way than a button.
  57. // Scroll down in menu.
  58. public void PointerScrollDown(object sender, PointerEventArgs e)
  59. {
  60. if(scrollRect.verticalNormalizedPosition >=0.1)
  61. {
  62. scrollRect.verticalNormalizedPosition-=0.1f;
  63. Debug.Log("SceneHandler.cs: Scroll down "+ e.target.name);
  64. }
  65. }
  66. public void PointerInside(object sender, PointerEventArgs e)
  67. {
  68. // Debug.Log("Object was entered");
  69. }
  70. public void PointerOutside(object sender, PointerEventArgs e)
  71. {
  72. // Debug.Log("Object was exited");
  73. }
  74. public PointerEventArgs getLaserClick()
  75. {
  76. return klicked;
  77. }
  78. }