VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
VRInput.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.EventSystems;
5 
6 using AVR;
7 using AVR.Core;
8 
9 namespace AVR.UI {
10  [RequireComponent(typeof(BaseInputModule))]
11  /// <summary>
12  /// This class overrides the base Input with Input from our VR components, thus enabling UI Interaction with a VR controller. The public attributes are automatically set by UIInteractionProvider.
13  /// </summary>
14  public class VRInput : BaseInput
15  {
16  /// <summary>
17  /// Singleton instance of this class. There should only be one VRInput component.
18  /// </summary>
19  public static VRInput Instance { get; private set; }
20 
21  private Camera eventCamera = null;
22 
23  public AVR_ControllerInputManager inputManager => AVR_UIInteractionProvider.currentActive?.controller?.inputManager;
24 
25  public AVR_ControllerInputManager.BoolEvent mouseButton0Click => AVR_UIInteractionProvider.currentActive ? AVR_UIInteractionProvider.currentActive.mouseButton0Click : AVR_ControllerInputManager.BoolEvent.ALWAYS_FALSE;
26  public AVR_ControllerInputManager.BoolEvent mouseButton0Down => AVR_UIInteractionProvider.currentActive ? AVR_UIInteractionProvider.currentActive.mouseButton0Down : AVR_ControllerInputManager.BoolEvent.ALWAYS_FALSE;
27  public AVR_ControllerInputManager.BoolEvent mouseButton0Up => AVR_UIInteractionProvider.currentActive ? AVR_UIInteractionProvider.currentActive.mouseButton0Up : AVR_ControllerInputManager.BoolEvent.ALWAYS_FALSE;
28  public AVR_ControllerInputManager.BoolEvent mouseButton1Click => AVR_UIInteractionProvider.currentActive ? AVR_UIInteractionProvider.currentActive.mouseButton1Click : AVR_ControllerInputManager.BoolEvent.ALWAYS_FALSE;
29  public AVR_ControllerInputManager.BoolEvent mouseButton1Down => AVR_UIInteractionProvider.currentActive ? AVR_UIInteractionProvider.currentActive.mouseButton1Down : AVR_ControllerInputManager.BoolEvent.ALWAYS_FALSE;
30  public AVR_ControllerInputManager.BoolEvent mouseButton1Up => AVR_UIInteractionProvider.currentActive ? AVR_UIInteractionProvider.currentActive.mouseButton1Up : AVR_ControllerInputManager.BoolEvent.ALWAYS_FALSE;
31 
32  /// <summary>
33  /// Sets a given camera to the current eventcamera. Typically called from AVR_UIInteractionprovider.
34  /// </summary>
35  /// <param name="eventCamera"> newly set eventcamera </param>
36  public void setEventCamera(Camera eventCamera) {
37  this.eventCamera = eventCamera;
38  foreach(AVR_Canvas c in AVR_Canvas.all_canvases) {
39  c.canvas.worldCamera = eventCamera;
40  }
41  }
42 
43  protected override void Awake()
44  {
45  if (Instance != null) GameObject.Destroy(Instance);
46  Instance = this;
47 
48  DontDestroyOnLoad(this);
49 
50  GetComponent<BaseInputModule>().inputOverride = this;
51  }
52 
53  public override bool mousePresent { get { return inputManager!=null; } }
54 
55  public override bool GetMouseButton(int button)
56  {
57  return button == 1 ?
58  inputManager && inputManager.getEventStatus(mouseButton1Click)
59  :
60  inputManager && inputManager.getEventStatus(mouseButton0Click)
61  ;
62  }
63 
64  public override bool GetMouseButtonDown(int button)
65  {
66  return button == 1 ?
67  inputManager && inputManager.getEventStatus(mouseButton1Down)
68  :
69  inputManager && inputManager.getEventStatus(mouseButton0Down)
70  ;
71  }
72 
73  public override bool GetMouseButtonUp(int button)
74  {
75  return button == 1 ?
76  inputManager && inputManager.getEventStatus(mouseButton1Up)
77  :
78  inputManager && inputManager.getEventStatus(mouseButton0Up)
79  ;
80  }
81 
82  public override Vector2 mousePosition
83  {
84  get
85  {
86  if(!eventCamera) return new Vector2(0,0);
87  return new Vector2(eventCamera.pixelWidth/2, eventCamera.pixelHeight/2);
88  }
89  }
90  }
91 }
BoolEvent
Boolean-returning events of a controller.
void setEventCamera(Camera eventCamera)
Sets a given camera to the current eventcamera. Typically called from AVR_UIInteractionprovider.
Definition: VRInput.cs:36
Manages inputs of a controller such as button presses and track-pad inputs.
override bool GetMouseButton(int button)
Definition: VRInput.cs:55
override bool GetMouseButtonUp(int button)
Definition: VRInput.cs:73
override void Awake()
Definition: VRInput.cs:43
override bool GetMouseButtonDown(int button)
Definition: VRInput.cs:64
This class overrides the base Input with Input from our VR components, thus enabling UI Interaction w...
Definition: VRInput.cs:14
static List< AVR_Canvas > all_canvases
A list of all AVR_Canvases that have at some point been active and not destroyed since ...
Definition: AVR_Canvas.cs:28
Represents a canvas for VR interaction purposes. Allows for interaction with the AVR_UIInteractionPro...
Definition: AVR_Canvas.cs:17