@GalLibba
OK, the legacy MagicLeapInputs input actions that come with SDK 1.12.1, do still work with our MagicLeapInputSimulator in MRTK3. However, it may need a smallish tweak in your script to get it working so that it works in Editor play mode with the simulator and, of course, on device.
TLDR: The reason it isn't working right away is that the MagicLeapInputSimulator device provides actions that bind better to the OpenXR input actions, and not the legacy MagicLeapInputs actions. However, we did accommodate for this in the simulator by overriding the legacy action paths to be able to bind to the same actions as OpenXR when running in Editor play mode with the simulator active. It just seems you need to use references to the input actions instead of creating the map directly in code. But the end result is very similar (see below) and works in either Editor play mode or on device:
[SerializeField]
private InputActionProperty _MLControllerBumper;
[SerializeField]
private InputActionProperty _MLControllerMenu;
void Start()
{
// Enable the InputActionMap so all actions within are enabled, similar to _mlInputs.Enable();
_MLControllerBumper.action?.actionMap?.Enable();
_MLControllerBumper.action.performed += HandleBumperPress;
_MLControllerBumper.action.canceled += HandleBumperRelease;
_MLControllerMenu.action.performed += HandleMenuPress;
_MLControllerMenu.action.canceled += HandleMenuRelease;
}
private void HandleBumperPress(InputAction.CallbackContext context)
{
Debug.Log("Bumper Was Pressed");
}
private void HandleBumperRelease(InputAction.CallbackContext context)
{
Debug.Log("Bumper Was Released");
}
private void HandleMenuPress(InputAction.CallbackContext context)
{
Debug.Log("Menu Was Pressed");
}
private void HandleMenuRelease(InputAction.CallbackContext context)
{
Debug.Log("Menu Was Released");
}
In the above script, you expose an InputActionProperty that you can wire up directly in the Inspector like so (check Use Reference and drag the input action from the MagicLeapInputs (or whatever input action asset) into the Reference field:
Doing it this way seems to allow the path override that we do in the MagicLeapInputSimulator to work so the simulated device properly binds to these legacy actions and you can subscribe to them. This should work on device too of course.
So in Editor play mode, when using the MagicLeapInputSimulator on screen controls, when I hit the Bumper and Menu buttons, I get the following in Console:
If you ever decide to update the project to latest SDK (currently 2.5.0) and transition to OpenXR, the above would still work, you would just drag the input actions from the OpenXR input action asset instead. In the MRTK3 package, we provide an input action asset for OpenXR located at: Packages/Magic Leap MRTK3/Runtime/XRProviders/OpenXR/Input/Actions/MagicLeapInputsOpenXR.inputactions.
Or, since there is no path override needed for the OpenXR actions, you could continue to create the maps directly in code as before, just using the OpenXR action classes instead like so (but only if transitioned to using OpenXR):
using UnityEngine;
using UnityEngine.InputSystem;
using MagicLeap.MRTK.Input;
public class ControllerTest : MonoBehaviour
{
private MagicLeapInputsOpenXR _mlInputs = null;
private MagicLeapInputsOpenXR.ControllerActions _MLControllerActions;
void Start()
{
_mlInputs = new MagicLeapInputsOpenXR();
_mlInputs.Enable();
_MLControllerActions = new MagicLeapInputsOpenXR.ControllerActions(_mlInputs);
_MLControllerActions.Bumper.performed += HandleBumperPress;
_MLControllerActions.Bumper.canceled += HandleBumperRelease;
}