protected override unsafe long ExecuteCommand(InputDeviceCommand *commandPtr)
        {
            var t = commandPtr->type;

            if (t == QueryEnabledStateCommand.Type)
            {
#if UNITY_EDITOR
                ((QueryEnabledStateCommand *)commandPtr)->isEnabled = m_Enabled;
#else
                ((QueryEnabledStateCommand *)commandPtr)->isEnabled = _iOSStepCounterIsEnabled(deviceId) != 0;
#endif
                return(kCommandSuccess);
            }

            if (t == EnableDeviceCommand.Type)
            {
                if (InputSystem.settings.iOS.motionUsage.enabled == false)
                {
                    Debug.LogError("Please enable Motion Usage in Input Settings before using Step Counter.");
                    return(kCommandFailure);
                }
#if UNITY_EDITOR
                m_Enabled = true;
                return(kCommandSuccess);
#else
                var callbacks = new iOSStepCounterCallbacks();
                callbacks.onData = OnDataReceived;
                return(_iOSStepCounterEnable(deviceId, ref callbacks, Marshal.SizeOf(callbacks)));
#endif
            }

            if (t == DisableDeviceCommand.Type)
            {
#if UNITY_EDITOR
                m_Enabled = false;
                return(kCommandSuccess);
#else
                return(_iOSStepCounterDisable(deviceId));
#endif
            }

            if (t == QueryCanRunInBackground.Type)
            {
                ((QueryCanRunInBackground *)commandPtr)->canRunInBackground = true;
                return(kCommandSuccess);
            }

            if (t == RequestResetCommand.Type)
            {
#if UNITY_EDITOR
                m_Enabled = false;
#else
                _iOSStepCounterDisable(deviceId);
#endif
                return(kCommandSuccess);
            }

            return(kCommandFailure);
        }
Example #2
0
        public unsafe long DeviceCommand(int deviceId, InputDeviceCommand *commandPtr)
        {
            if (commandPtr == null)
            {
                throw new System.ArgumentNullException(nameof(commandPtr));
            }

            return(NativeInputSystem.IOCTL(deviceId, commandPtr->type, new IntPtr(commandPtr->payloadPtr), commandPtr->payloadSizeInBytes));
        }
        private static unsafe long?InputSystemOnDeviceCommand(InputDevice device, InputDeviceCommand *command)
        {
            if (command->type != QueryCanRunInBackground.Type)
            {
                // return null is skip this evaluation
                return(null);
            }

            ((QueryCanRunInBackground *)command)->canRunInBackground = true;
            return(InputDeviceCommand.GenericSuccess);
        }
        public unsafe long DeviceCommand(int deviceId, InputDeviceCommand *commandPtr)
        {
            lock (m_Lock)
            {
                if (m_DeviceCommandCallbacks != null)
                {
                    foreach (var entry in m_DeviceCommandCallbacks)
                    {
                        if (entry.Key == deviceId)
                        {
                            return(entry.Value(deviceId, commandPtr));
                        }
                    }
                }
            }

            return(-1);
        }
        public unsafe long DeviceCommand(int deviceId, InputDeviceCommand *commandPtr)
        {
            lock (m_Lock)
            {
                if (commandPtr->type == QueryPairedUserAccountCommand.Type)
                {
                    foreach (var pairing in userAccountPairings)
                    {
                        if (pairing.deviceId != deviceId)
                        {
                            continue;
                        }

                        var queryPairedUser = (QueryPairedUserAccountCommand *)commandPtr;
                        queryPairedUser->handle = pairing.userHandle;
                        queryPairedUser->name   = pairing.userName;
                        queryPairedUser->id     = pairing.userId;
                        return((long)QueryPairedUserAccountCommand.Result.DevicePairedToUserAccount);
                    }
                }

                var result = InputDeviceCommand.kGenericFailure;
                if (m_DeviceCommandCallbacks != null)
                {
                    foreach (var entry in m_DeviceCommandCallbacks)
                    {
                        if (entry.Key == deviceId)
                        {
                            result = entry.Value(deviceId, commandPtr);
                            if (result >= 0)
                            {
                                return(result);
                            }
                        }
                    }
                }
                return(result);
            }
        }
Example #6
0
        private static unsafe long?OnDeviceCommand(InputDevice device, InputDeviceCommand *command)
        {
            if (device != s_State.attitude && device != s_State.gyroscope && device != s_State.gravity &&
                device != s_State.linearAcceleration)
            {
                return(null);
            }

            if (command->type == SetSamplingFrequencyCommand.Type)
            {
                s_State.gyroUpdateInterval = ((SetSamplingFrequencyCommand *)command)->frequency;
                InputRuntime.s_Instance.SetUnityRemoteGyroUpdateInterval(s_State.gyroUpdateInterval);
                return(InputDeviceCommand.GenericSuccess);
            }

            if (command->type == QuerySamplingFrequencyCommand.Type)
            {
                ((QuerySamplingFrequencyCommand *)command)->frequency = s_State.gyroUpdateInterval;
                return(InputDeviceCommand.GenericSuccess);
            }

            return(InputDeviceCommand.GenericFailure);
        }
 public unsafe long DeviceCommand(int deviceId, InputDeviceCommand *commandPtr)
 {
     return(NativeInputSystem.IOCTL(deviceId, commandPtr->type, new IntPtr(commandPtr->payloadPtr), commandPtr->payloadSizeInBytes));
 }
Example #8
0
 protected virtual unsafe long ExecuteCommand(InputDeviceCommand *commandPtr)
 {
     return(InputRuntime.s_Instance.DeviceCommand(deviceId, commandPtr));
 }