Ejemplo n.º 1
0
    public void Devices_CanDisableOnScreenButtonFromPressEvent()
    {
        var gameObject = new GameObject();
        var button     = gameObject.AddComponent <OnScreenButton>();

        button.controlPath = "<Keyboard>/a";

        // Add a second button so that the device doesn't go away when we disable
        // the first one.
        new GameObject().AddComponent <OnScreenButton>().controlPath = "<Keyboard>/b";

        // When we disable the OnScreenComponent, the keyboard goes away, so use a state monitor
        // to observe the change.
        bool?isPressed = null;

        InputState.AddChangeMonitor(Keyboard.current.aKey,
                                    (control, time, eventPtr, index) =>
        {
            isPressed = ((ButtonControl)control).isPressed;
        });

        button.OnPointerDown(null);
        InputSystem.Update();

        Assert.That(isPressed, Is.True);

        isPressed = null;
        gameObject.SetActive(false);
        InputSystem.Update();

        Assert.That(isPressed, Is.False);
    }
Ejemplo n.º 2
0
    public void Events_CanChangeStateOfDeviceDirectlyUsingEvent()
    {
        var mouse = InputSystem.AddDevice <Mouse>();

        using (StateEvent.From(mouse, out var eventPtr))
        {
            var stateChangeMonitorTriggered = false;
            InputState.AddChangeMonitor(mouse.delta,
                                        (c, t, e, i) => stateChangeMonitorTriggered = true);

            mouse.delta.WriteValueIntoEvent(new Vector2(123, 234), eventPtr);

            InputState.Change(mouse, eventPtr);

            Assert.That(stateChangeMonitorTriggered, Is.True);
            Assert.That(mouse.delta.ReadValue(), Is.EqualTo(new Vector2(123, 234)).Using(Vector2EqualityComparer.Instance));
        }
    }
Ejemplo n.º 3
0
        protected void InstallStateChangeMonitors(int startIndex = 0)
        {
            ////REVIEW: just bind to the entire pointer state instead of to individual controls?
            for (var i = startIndex; i < m_NumSources; ++i)
            {
                var pointer = m_Sources[i];

                // Monitor position.
                InputState.AddChangeMonitor(pointer.position, this, i);

                // Monitor any button that isn't synthetic.
                var buttonIndex = 0;
                foreach (var control in pointer.allControls)
                {
                    if (control is ButtonControl button && !button.synthetic)
                    {
                        InputState.AddChangeMonitor(button, this, ((long)(uint)buttonIndex << 32) | (uint)i);
                        ++buttonIndex;
                    }
                }
            }
        }