3.6. C# XrInput¶
3.6.1. InputManager.cs¶
The InputManager
will detect and create the VR controllers. It handles getting of the current input state, i.e. which buttons are pressed, and saves this into the InputState
. The InputManager
and the InputState
will also handle shared functionality, e.g. which tool is active, what the brush size is.
-
class
XrInput.InputManager
: public MonoBehaviour¶ This script handles the controller input and is based on the Unity XR Interaction Toolkit. An important part is that this is where the InputState can be accessed and is updated.
Public Functions
-
void
RepaintInputHints
(bool left = true, bool right = true)¶ Safely repaint the input hints on the controllers, specify which hands should be repainted.
Public Members
-
InputDeviceCharacteristics
handCharL
= InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.Left¶
-
InputDevice
HandL
¶
-
UiInputHints
HandHintsL
¶
-
InputDeviceCharacteristics
handCharR
= InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.Right¶
-
InputDevice
HandR
¶
-
UiInputHints
HandHintsR
¶
Events
Public Static Attributes
-
InputManager
get
¶ The singleton instance.
-
InputState
State
¶ The current input state shared between all meshes.
-
InputState
StatePrev
¶ Input at the last frame (main thread).
Private Functions
-
void
Awake
()¶
-
void
Start
()¶
-
void
Update
()¶
-
bool
InitializeController
(bool isRight, InputDeviceCharacteristics characteristics, out InputDevice inputDevice, GameObject handPrefab, XRController modelParent, out Animator handAnimator, out UiInputHints inputHints, out XrBrush brush)¶ Gets the XR InputDevice and sets the correct model to display. This is where a controller is detected and initialized.
- Return
True if successful
-
void
UpdateHandAnimators
()¶
-
void
UpdateRayInteractors
()¶ Enables and disables certain rays and UI interaction for performance. Raycasting the UI is one of the most expensive operations currently. See profile EventSystem
Updates the InputState State. Implementation note: The hands may not be initialized/detected yet.
Private Members
-
bool
useHands
= false¶
-
GameObject
handPrefabL
= default¶
-
GameObject
handPrefabR
= default¶
-
List<GameObject>
controllerPrefabs
= default¶
-
XRController
handRigL
= default¶
-
XRRayInteractor
handInteractorL
= default¶
-
readonly List<XRBaseInteractable>
_rayHoverTargetsL
= new List<XRBaseInteractable>()¶
-
XRController
handRigR
= default¶
-
XRRayInteractor
handInteractorR
= default¶
-
readonly List<XRBaseInteractable>
_rayHoverTargetsR
= new List<XRBaseInteractable>()¶
-
XRRayInteractor
teleportRayL
= default¶ The ray interactor for teleporting
-
bool
_prevAxisClickPressedL
¶
-
bool
_prevAxisClickPressedR
¶
-
void
3.6.2. InputState.cs¶
-
struct
XrInput.InputState
¶ This is the ‘shared’ input state. It is also where you can access the filtered controller input. Stores input that is shared between meshes as well as the raw input that has not been mapped to actions. Raw input has been filtered to prevent conflicts with UI and grabbables.
Public Functions
-
void
TogglePivotMode
()¶ Changes the pivot mode depending on the ActiveTool
Public Members
-
float
GripL
¶
-
float
TriggerL
¶
-
float
GripR
¶
-
float
TriggerR
¶
-
Vector3
HandPosL
¶
-
Vector3
HandPosR
¶
-
Quaternion
HandRotL
¶
-
Quaternion
HandRotR
¶
-
bool
PrimaryBtnL
¶
-
bool
SecondaryBtnL
¶
-
Vector2
PrimaryAxisL
¶
-
bool
PrimaryBtnR
¶
-
bool
SecondaryBtnR
¶
-
Vector2
PrimaryAxisR
¶
-
bool
IsTeleporting
¶ Are we pressing the teleport button? Used to disable other input.
-
float
BrushRadius
¶
-
bool
TransformWithRotate
¶ Is rotation enabled for transformations.
-
SelectionMode
ActiveSelectionMode
¶
-
bool
NewSelectionOnDraw
¶ Draw into a new selection with each stroke
-
bool
DiscardSelectionOnDraw
¶ Clear the selection when starting a stroke
-
bool
BoundsVisible
¶ Should we show the bounding boxes of the editable meshes
Properties
-
PivotMode
ActivePivotMode
{ }¶ The pivot mode for the ActiveTool
-
ToolTransformMode
ToolTransformMode
{ }¶ The sub-state of the Transform tool
-
ToolSelectMode
ToolSelectMode
{ }¶ The sub-state of the Select tool
Public Static Functions
-
InputState
GetInstance
()¶ - Return
An instance with the defaults set
-
void
3.6.2.1. Enums¶
-
enum
XrInput.ToolType
¶ Which tool is being used, InputState.ActiveTool.
Values:
-
Transform
¶
-
Select
¶
-
-
enum
XrInput.ToolSelectMode
¶ The sub-state of the Select tool.
Values:
-
Idle
¶
-
Selecting
¶
-
TransformingL
¶
-
TransformingR
¶
-
TransformingLr
¶
-
3.6.3. XrBrush.cs¶
-
class
XrInput.XrBrush
: public MonoBehaviour¶ Functionality related to the sphere ‘bubble’ brush. Currently handles resizing the brush, getting the center and finding overlapping bounding boxes via trigger colliders.
Public Functions
-
void
SetRadius
(float value)¶
-
void
Initialize
(bool isRight)¶
-
void
OnActiveToolChanged
()¶
-
bool
SetActiveMesh
()¶ Will set the active mesh as the first hovered, if we are not hovering over the active mesh. Hovering is detected and visualized by the bounding boxes.
- Return
True if the active mesh has been set
Public Members
-
const float
ResizeSpeed
= 0.5f¶
-
const float
ResizeDeadZone
= 0.1f¶
-
bool
InsideActiveMeshBounds
¶
Public Static Attributes
-
Vector2
RadiusRange
= new Vector2(0.025f, 1f)¶
Private Functions
-
void
OnDestroy
()¶
-
void
OnTriggerEnter
(Collider other)¶ Called when the brush bubble enters a trigger collider. Standard Unity callback. We use this to set the hovering status of the individual meshes.
-
void
MeshLeftTrigger
(LibiglMesh libiglMesh)¶ Called when the mesh leaves the trigger and updates the hovering status of a mesh. Implementation note: split into separate function so when deactivating we leave all triggers.
-
void
RepaintBoundingBoxes
()¶ Repaint bounding boxes based on the hovering status. Bounds are hidden if we are hovering over the active mesh. The first hovered mesh is set as the primary one.
-
void
OnActiveMeshChanged
()¶ Called by the event MeshManager.OnActiveMeshChanged
-
void
OnDisable
()¶
Private Members
-
SphereCollider
_brushCollider
¶
-
bool
_isRight
¶
-
readonly List<LibiglMesh>
_currentLibiglMeshes
= new List<LibiglMesh>()¶
-
void