示例#1
0
        /// <inheritdoc />
        public override void Enable()
        {
            if (!Application.isPlaying)
            {
                return;
            }

            if (!inputHandle.IsValid)
            {
                if (MlInput.MLInputCreate(inputConfiguration, ref inputHandle).IsOk)
                {
                    if (MlInput.MLInputGetControllerState(inputHandle, statePointer).IsOk)
                    {
                        MlInput.MLInputControllerState.GetControllerStates(statePointer, ref controllerStates);
                    }
                    else
                    {
                        Debug.LogError("Failed to update the controller input state!");
                    }

                    MlInput.MLInputControllerCallbacksEx.OnConnect    += MlInputControllerCallbacksEx_OnConnect;
                    MlInput.MLInputControllerCallbacksEx.OnDisconnect += MlInputControllerCallbacksEx_OnDisconnect;

                    if (!MlInput.MLInputSetControllerCallbacksEx(inputHandle, in controllerCallbacks, IntPtr.Zero).IsOk)
                    {
                        Debug.LogError("Failed to set controller callbacks!");
                    }
                }
                else
                {
                    Debug.LogError("Failed to create input tracker!");
                }
            }

            if (!controllerHandle.IsValid)
            {
                if (!MlController.MLControllerCreateEx(controllerConfiguration, ref controllerHandle).IsOk)
                {
                    Debug.LogError("Failed to create controller tracker!");
                }
                else
                {
                    MlController.MLControllerGetState(controllerHandle, ref controllerSystemState);
                }
            }
        }
示例#2
0
        /// <inheritdoc />
        public override void Update()
        {
            base.Update();

            if (!Application.isPlaying)
            {
                return;
            }
            if (!inputHandle.IsValid)
            {
                return;
            }
            if (!controllerHandle.IsValid)
            {
                return;
            }

            if (MlInput.MLInputGetControllerState(inputHandle, statePointer).IsOk)
            {
                MlInput.MLInputControllerState.GetControllerStates(statePointer, ref controllerStates);
            }
            else
            {
                Debug.LogError("Failed to update the controller input state!");
            }

            if (!MlController.MLControllerGetState(controllerHandle, ref controllerSystemState).IsOk)
            {
                Debug.LogError("Failed to get the controller system state!");
            }

            for (int i = 0; i < controllerStates.Length; i++)
            {
                if (controllerStates[i].is_connected &&
                    !activeControllers.ContainsKey(controllerStates[i].hardware_index))
                {
                    GetController(controllerStates[i].hardware_index);
                }
            }

            foreach (var controller in activeControllers)
            {
                controller.Value?.UpdateController(controllerStates[controller.Key], controllerSystemState.controller_state[controller.Key]);
            }
        }