IMHOTEP Framework
|
The IMHOTEP input system contains an abstract interface to the input devices, so that - for the most part - the developer does not need to worry about whether a mouse or controller is active.
It also tries to stay as close as possible to the standard Unity input system, which means that events are raised in a similar manner. However, there are places where the system is slightly different to the standard Unity input system, for example because we need additional buttons for the controllers.
Note: To simplify things, the trigger of the right controller is handled in the same way as a click with the left mouse button.
Generally, any GameObject can receive input events when it is being clicked, pointed at etc. To receive these events, you need to:
To be able to receive events, the specific interface needs to be implemented. For example, the ToolChoise class listenes to the click event. This is done by "inheriting" the interface IPointerClickHandler and implementing its method "OnPointerClick":
Note: You'll need to include the Unity EventSystem at the top of your file:
The PointerEventData can be used to check where the object was clicked, which button was clicked (right, middle, left), what the texture-coordinates at that position are etc. See the Unity documentation on 'PointerEventData' for more details.
A lot of the Unity event interfaces are also implemented in IMHOTEP. The most commonly used events are probably:
Custom events added by us:
Note: When you've clicked on (or hovered over) an object, the texture coordinates are passed along as well. However, since Unity does not pass these along, the PointerEventData which we send to the above events is actually a CustomEventData, which holds this extra information (it inherits from PointerEventData. To access the texture coordinate of the hit position, you can cast the PointerEventData to a CustomEventData:
See also CustomEventData.
The interface above abstracts the events so that in many cases, you don't need to worry about whether the mouse or the controllers are active. However, there are some times when you do need to handle the mouse and the controllers differently. For this, you can retrieve the current input device:
First, you should check which type of input we're currently getting:
In case the mouse is active, you can use Unity's standard Input class to get the Mouse Position and speed etc. For example:
If the Vive controllers are active, you can cast the input device to a Controller:
If the Vive controller is active then the other controller can be accessed by (Note: always check if lc
is not null - it might not be set if the controller is currently not tracked!)
In both cases, you can check whether the trigger is pressed, where the controller is, how it's oriented etc. (see Controller for details):