コード例 #1
0
        public void RemoveStateChangeMonitor(InputControl control, IInputStateChangeMonitor monitor, long monitorIndex)
        {
            if (m_StateChangeMonitors == null)
            {
                return;
            }

            var device      = control.device;
            var deviceIndex = device.m_DeviceIndex;

            // Ignore if device has already been removed.
            if (deviceIndex == InputDevice.kInvalidDeviceIndex)
            {
                return;
            }

            // Ignore if there are no state monitors set up for the device.
            if (deviceIndex >= m_StateChangeMonitors.Length)
            {
                return;
            }

            m_StateChangeMonitors[deviceIndex].Remove(monitor, monitorIndex, isProcessingEvents);

            // Remove pending timeouts on the monitor.
            for (var i = 0; i < m_StateChangeMonitorTimeouts.length; ++i)
            {
                if (m_StateChangeMonitorTimeouts[i].monitor == monitor &&
                    m_StateChangeMonitorTimeouts[i].monitorIndex == monitorIndex)
                {
                    m_StateChangeMonitorTimeouts[i] = default;
                }
            }
        }
コード例 #2
0
        ////TODO: support combining monitors for bitfields
        public void AddStateChangeMonitor(InputControl control, IInputStateChangeMonitor monitor, long monitorIndex, uint groupIndex)
        {
            Debug.Assert(m_DevicesCount > 0);

            var device      = control.device;
            var deviceIndex = device.m_DeviceIndex;

            Debug.Assert(deviceIndex != InputDevice.kInvalidDeviceIndex);

            // Allocate/reallocate monitor arrays, if necessary.
            // We lazy-sync it to array of devices.
            if (m_StateChangeMonitors == null)
            {
                m_StateChangeMonitors = new StateChangeMonitorsForDevice[m_DevicesCount];
            }
            else if (m_StateChangeMonitors.Length <= deviceIndex)
            {
                Array.Resize(ref m_StateChangeMonitors, m_DevicesCount);
            }

            // If we have removed monitors
            if (!isProcessingEvents && m_StateChangeMonitors[deviceIndex].needToCompactArrays)
            {
                m_StateChangeMonitors[deviceIndex].CompactArrays();
            }

            // Add record.
            m_StateChangeMonitors[deviceIndex].Add(control, monitor, monitorIndex, groupIndex);
        }
コード例 #3
0
 public void AddStateChangeMonitorTimeout(InputControl control, IInputStateChangeMonitor monitor, double time, long monitorIndex, int timerIndex)
 {
     m_StateChangeMonitorTimeouts.Append(
         new StateChangeMonitorTimeout
     {
         control      = control,
         time         = time,
         monitor      = monitor,
         monitorIndex = monitorIndex,
         timerIndex   = timerIndex,
     });
 }
コード例 #4
0
        public void RemoveStateChangeMonitorTimeout(IInputStateChangeMonitor monitor, long monitorIndex, int timerIndex)
        {
            var timeoutCount = m_StateChangeMonitorTimeouts.length;

            for (var i = 0; i < timeoutCount; ++i)
            {
                ////REVIEW: can we avoid the repeated array lookups without copying the struct out?
                if (ReferenceEquals(m_StateChangeMonitorTimeouts[i].monitor, monitor) &&
                    m_StateChangeMonitorTimeouts[i].monitorIndex == monitorIndex &&
                    m_StateChangeMonitorTimeouts[i].timerIndex == timerIndex)
                {
                    m_StateChangeMonitorTimeouts[i] = default;
                    break;
                }
            }
        }
コード例 #5
0
    public void State_StateChangeMonitorTimeout_CanBeAddedFromMonitorCallback()
    {
        var gamepad = InputSystem.AddDevice <Gamepad>();

        var monitorFired = false;
        var timeoutFired = false;

        IInputStateChangeMonitor monitor = null;

        monitor = InputSystem.AddStateChangeMonitor(gamepad.leftStick,
                                                    (control, time, eventPtr, monitorIndex) =>
        {
            Assert.That(!monitorFired);
            monitorFired = true;
            InputSystem.AddStateChangeMonitorTimeout(gamepad.leftStick, monitor,
                                                     runtime.currentTime + 1);
        }, timerExpiredCallback:
                                                    (control, time, monitorIndex, timerIndex) =>
        {
            Assert.That(!timeoutFired);
            timeoutFired = true;
        });

        // Trigger monitor callback.
        InputSystem.QueueStateEvent(gamepad, new GamepadState {
            leftStick = Vector2.one
        });
        InputSystem.Update();

        Assert.That(monitorFired);

        // Expire timer.
        runtime.currentTime += 2;
        InputSystem.Update();

        Assert.That(timeoutFired);
    }
コード例 #6
0
        public void SignalStateChangeMonitor(InputControl control, IInputStateChangeMonitor monitor)
        {
            var device      = control.device;
            var deviceIndex = device.m_DeviceIndex;

            ref var monitorsForDevice = ref m_StateChangeMonitors[deviceIndex];