API Overview
Controller API Overview
This section provides an overview on how to use Unity's Input System to access Magic Leap 2's controller input.
- First create a new instance of
MagicLeapInputs
and initialize it by calling.Enable()
.
note
The MagicLeapInputs
is an auto generated class that creates a dynamic instance of an InputActionAsset
which includes predefined Action Maps that correspond to all of the Magic Leap 2's input.
- Create an instance of
MagicLeapInputs.ControllerActions
, passing in an instance of theMagicLeapInputs
.
note
The MagicLeapInputs.ControllerActions
is an Action Map that was auto-generated by the Unity Input System and includes predefined bindings for the Magic Leap 2 Controller Input Events.
- Subscribe to the input using the events in the
ControllerActions
and read input values using the Input Action'sCallbackContext
or read the Input Action's values directly usingInputAction.ReadValue<T>()
.
note
View Unity's InputActions
Documentation for more information on how to read values from the callback.
private MagicLeapInputs mlInputs;
private MagicLeapInputs.ControllerActions controllerActions;
void Start()
{
mlInputs = new MagicLeapInputs();
mlInputs.Enable();
controllerActions = new MagicLeapInputs.ControllerActions(mlInputs);
controllerActions.Bumper.performed += HandleOnBumper;
}
private void HandleOnBumper(InputAction.CallbackContext obj)
{
bool bumperDown = obj.ReadValueAsButton();
Debug.Log("The Bumper is pressed down " + bumperDown);
}
void OnDestroy()
{
mlInputs.Dispose();
}
Input Table
The following inputs can be accessed via ControllerActions
Name | Type | ControlType | InitialStateCheck | Description |
---|---|---|---|---|
Position | Value | Vector3 | TRUE | The position of the controller in world space |
Rotation | Value | Quaternion | TRUE | The rotation of the controller in world space |
Trigger | Value | Analog | TRUE | An analog value between 0-1 corresponding to how far the trigger is pressed. Its activation range and "dead zone" can be assigned under Project Settings > Input System Package |
Bumper | Button | Button | TRUE | A digital value that corresponds to the pressing of the bumper button above the trigger |
Touchpad1Position | Value | Vector2 | TRUE | The XY position of the first touch on the touchpad, where the center is 0,0 and the XY values are between -1 and 1 |
Touchpad1 | Value | Button | TRUE | A digital value that corresponds to the pressing of the touchpad as a button |
Touchpad1Force | Value | Analog | TRUE | An analog value between 0-1 that corresponds to how hard the touchpad is pressed |
Touchpad2 | Value | Vector2 | TRUE | The XY position of the second touch on the touchpad, where the center is 0,0 and the XY values are between -1 and 1 |
Menu | Button | Button | FALSE | A digital value that corresponds to the pressing of the menu button (above the home button) |
IsTracked | Pass-Through | -- | TRUE | A digital value that represents whether the controller is currently connected and tracked |