## [Input]()
## Table of Contents
- [Overview](#overview)
- [Input System Diagrams](#input-system-diagrams)
- [Input Module Design](#input-module-design)
- [Prefabs](#prefabs)
- [Scripts](#scripts)
- [Test Prefabs](#test-prefabs)
- [Test Scripts](#test-scripts)
- [Tests](#tests)
## Overview
This contains a fully-featured **input system**, which allows you to handle various types of input and send them to any game object being currently gazed at, or any fallback object. It also includes a few example cursors, similar to the HoloLens shell cursor, that fully leverages the Unity's animation system. This input system uses Unity's default **EventSystem** and there's no need for a custom **input module**. The default **Standalone Input Module** works with this input system.
## Input System Diagrams:
![alt text](/External/ReadMeImages/InputSystemDiagram.png)
![alt text](/External/ReadMeImages/CursorSystemDiagram.PNG)
### Input Module Design
The input module is designed to be extensible: it could support various input mechanisms and various types of gazers.
Each input source (hands, gestures, others) implement a **IInputSource** interface. The interface defines various events that the input sources can trigger. The input sources register themselves with the InputManager, whose role it is to forward input to the appropriate game objects. Input sources can be dynamically enabled / disabled as necessary, and new input sources can be created to support different input devices.
Game objects that want to consume input events can implement one or many **input interfaces**, such as:
- **IFocusable** for focus enter and exit. The focus can be triggered by the user's gaze or any other gaze source.
- **IHoldHandle** for the Windows hold gesture.
- **IInputHandler** for source up and down. The source can be a hand that tapped, a clicker that was pressed, etc.
- **IInputClickHandler** for source clicked. The source can be a hand that tapped, a clicker that was pressed, etc.
- **IManipulationHandler** for the Windows manipulation gesture.
- **INavigationHandler** for the Windows navigation gesture.
- **ISourceStateHandler** for the source detected and source lost events.
- **ISpeechHandler** for voice commands.
- **IDictationHandler** for speech to text dictation.
- **IGamePadHandler** for generic gamepad events.
- **IXboxControllerHandler** for Xbox One Controller events.
- **IBoundingBoxStateHandler** for Bounding Box Rig events.
The **input manager** listens to the various events coming from the input sources, and also takes into account the gaze. Currently, that gaze is always coming from the GazeManager class, but this could be extended to support multiple gaze sources if the need arises.
By default, input events are sent to the currently focused game object, if that object implements the appropriate interface. Modals input handlers can also be added to the input manager: these modal handlers will take priority over the currently focused object Fallback handlers can also be defined, so that the application can react to global inputs that aren't targeting a specific element. Any event sent by the input manager always bubbles up from the object to its ancestors.
In recap, the **input manager** forwards the various input sources events to the appropriate game object, using the following order:
1. The registered modal input handlers, in LIFO (Last-In First-Out) order of registration
2. The currently focused object
3. The fallback input handlers, in LIFO order of registration
### [Prefabs](Prefabs)
Prefabs related to the input features.
#### BasicCursor.prefab
Torus shaped basic cursor that follows the user's gaze around.
#### Cursor.prefab
Torus shaped CursorOnHolograms when user is gazing at holograms and point light CursorOffHolograms when user is gazing away from holograms.
#### CursorWithFeedback.prefab
Torus shaped cursor that follows the user's gaze and HandDetectedFeedback asset to give feedback to user when their hand is detected in the ready state.
#### DefaultCursor.prefab
3D animated cursor that follows the user's gaze and uses the Unity animation system to handle its various states. This cursor imitates the HoloLens Shell cursor.
#### HoloLensCamera.prefab
Unity camera that has been customized for Holographic development.
1. Camera.Transform set to 0,0,0
2. 'Clear Flags' changed to 'Solid Color'
3. Color set to R:0, G:0, B:0, A:0 as black renders transparent in HoloLens.
4. Set the recommended near clipping plane.
5. Allows manual movement of the camera when in editor
#### InputManager.prefab
Input system that manages gaze and various input sources currently supported by HoloLens, such as hands and gestures.
This also includes a fake input source that allows you to simulate input when in the editor. By default, this can be done by holding Shift (left input source) or Space (right input source), moving the mouse to move the source and using the left mouse button to tap.
#### MixedRealityCamera.prefab
Camera capabale of rendering for HoloLens and occluded Windows Mixed Reality enabled devices.
MixedRealityCameraManager.cs exposes some defaults for occluded aka opaque displays Vs HoloLens.
You can either use the defaults that have been set or customize them to match your application requirements.
**For HoloLens:**
1. 'Clear Flags' is set to 'Solid Color' and Color to 'Clear' as black renders transparent in HoloLens.
2. Near clip plane is set to 0.85 per comfort recommendations.
3. Quality Settings to be Fastest.
**For occluded aka opaque devices:**
1. 'Clear Flags' is set to Skybox
2. Near clip plane is set to 0.3 which is typical for VR applications.
3. Quality Settings to be Fantastic as it uses the PC GPU to render content.
#### MixedRealityCameraParent.prefab
This prefab is used when you want to enable teleporting on mixed reality enabled occluded devices.
In order to prevent the MainCamera position from being overwritten in the next update we use a parent GameObject.
#### MixedRealityCameraParentWithControllers.prefab
This prefab is used when you want to enable teleporting on mixed reality enabled occluded devices, as well as motion controller visualization.
In order to prevent the MainCamera position from being overwritten in the next update we use a parent GameObject.
### [Scripts](Scripts)
Scripts related to the input features.
##### ControllerVisualizer.cs
Use this to visualize a 6DoF controller in your application. Add this script to a GameObject as a child of the MainCamera, or use the MixedRealityCameraParentWithControllers prefab. Either specify a shader to use for the [glTF](https://www.khronos.org/gltf) model or add GameObject overrides to represent the controllers.
- **leftControllerOverride** [Optional] A prefab to spawn to represent the left controller. This will automatically move and reorient when the controller is moved.
- **rightControllerOverride** [Optional] A prefab to spawn to represent the right controller. This will automatically move and reorient when the controller is moved.
- **touchpadTouchedOverride** [Optional] A prefab to spawn to represent the user's touch location on the touchpad. This will automatically move when the user moves their touch location. Default is a sphere.
- **GLTFShader** [Optional, if using overrides] If using the controller's built-in [glTF](https://www.khronos.org/gltf) model, this will be the shader applied to the resulting GameObject.
##### ControllerDebug.cs
This can be used to load a [glTF](https://www.khronos.org/gltf) file in the editor, as well as displaying input and source data from motion controllers on a text panel for debugging purposes on the device.
- **LoadGLTFFile** A boolean to specify if a glTF file should be loaded from StreamingAssets.
- **GLTFName** The name of the GLTF file to be loaded from StreamingAssets.
- **touchpadTouchedOverride** [Optional] A prefab to spawn on the touchpad of the glTF file specified. Default is a sphere.
- **GLTFShader** [Opti