Esempio n. 1
0
    public void EnhancedTouch_TouchSimulation_CanAddAndRemovePointerDevices()
    {
        TouchSimulation.Enable();

        var pointer = InputSystem.AddDevice <Pointer>();

        Press(pointer.press);

        Assert.That(Touch.activeTouches, Has.Count.EqualTo(1));

        InputSystem.RemoveDevice(pointer);

        ////FIXME: This doesn't work yet as TouchSimulation isn't using events and Touch ignores input that isn't from events
        //Assert.That(Touch.activeTouches, Is.Empty);
    }
Esempio n. 2
0
    public void EnhancedTouch_TouchSimulation_ProducesPrimaryTouches()
    {
        var mouse = InputSystem.AddDevice <Mouse>();

        TouchSimulation.Enable();

        Set(mouse.position, new Vector2(123, 234));
        Press(mouse.leftButton);

        Assert.That(TouchSimulation.instance.simulatedTouchscreen.press.ReadValue(), Is.EqualTo(1).Within(0.00001));
        Assert.That(TouchSimulation.instance.simulatedTouchscreen.primaryTouch.touchId.ReadValue(), Is.EqualTo(1));
        Assert.That(TouchSimulation.instance.simulatedTouchscreen.primaryTouch.phase.ReadValue(), Is.EqualTo(TouchPhase.Began));
        Assert.That(TouchSimulation.instance.simulatedTouchscreen.position.ReadValue(),
                    Is.EqualTo(new Vector2(123, 234)).Using(Vector2EqualityComparer.Instance));
        Assert.That(TouchSimulation.instance.simulatedTouchscreen.delta.ReadValue(),
                    Is.EqualTo(Vector2.zero).Using(Vector2EqualityComparer.Instance));

        Set(mouse.position, new Vector2(234, 345));

        Assert.That(TouchSimulation.instance.simulatedTouchscreen.press.ReadValue(), Is.EqualTo(1).Within(0.00001));
        Assert.That(TouchSimulation.instance.simulatedTouchscreen.primaryTouch.touchId.ReadValue(), Is.EqualTo(1));
        Assert.That(TouchSimulation.instance.simulatedTouchscreen.primaryTouch.phase.ReadValue(), Is.EqualTo(TouchPhase.Moved));
        Assert.That(TouchSimulation.instance.simulatedTouchscreen.position.ReadValue(),
                    Is.EqualTo(new Vector2(234, 345)).Using(Vector2EqualityComparer.Instance));
        Assert.That(TouchSimulation.instance.simulatedTouchscreen.delta.ReadValue(),
                    Is.EqualTo(new Vector2(111, 111)).Using(Vector2EqualityComparer.Instance));

        InputSystem.Update();

        Assert.That(TouchSimulation.instance.simulatedTouchscreen.press.ReadValue(), Is.EqualTo(1).Within(0.00001));
        Assert.That(TouchSimulation.instance.simulatedTouchscreen.primaryTouch.touchId.ReadValue(), Is.EqualTo(1));
        Assert.That(TouchSimulation.instance.simulatedTouchscreen.primaryTouch.phase.ReadValue(), Is.EqualTo(TouchPhase.Moved));
        Assert.That(TouchSimulation.instance.simulatedTouchscreen.position.ReadValue(),
                    Is.EqualTo(new Vector2(234, 345)).Using(Vector2EqualityComparer.Instance));
        Assert.That(TouchSimulation.instance.simulatedTouchscreen.delta.ReadValue(),
                    Is.EqualTo(Vector2.zero).Using(Vector2EqualityComparer.Instance));
    }
Esempio n. 3
0
    public void EnhancedTouch_CanEnableAndDisableTouchSimulation()
    {
        Assert.That(InputSystem.devices, Has.None.TypeOf <Touchscreen>());

        TouchSimulation.Enable();

        Assert.That(InputSystem.devices, Has.Exactly(1).TypeOf <Touchscreen>());
        Assert.That(TouchSimulation.instance, Is.Not.Null);
        Assert.That(TouchSimulation.instance.simulatedTouchscreen, Is.Not.Null);
        Assert.That(TouchSimulation.instance.simulatedTouchscreen, Is.SameAs(Touchscreen.current));

        TouchSimulation.Disable();

        Assert.That(InputSystem.devices, Has.None.TypeOf <Touchscreen>());

        // Make sure we can re-enable it.
        TouchSimulation.Enable();

        Assert.That(InputSystem.devices, Has.Exactly(1).TypeOf <Touchscreen>());

        TouchSimulation.Destroy();

        Assert.That(TouchSimulation.instance, Is.Null);
    }
Esempio n. 4
0
    public void EnhancedTouch_CanSimulateTouchInputFrom(string layoutName)
    {
        var pointer = (Pointer)InputSystem.AddDevice(layoutName);

        TouchSimulation.Enable();

        Set(pointer.position, new Vector2(123, 234));
        Press(pointer.press);

        Assert.That(Touch.activeTouches, Has.Count.EqualTo(1));
        Assert.That(Touch.activeTouches[0].touchId, Is.EqualTo(1));
        Assert.That(Touch.activeTouches[0].screen, Is.SameAs(TouchSimulation.instance.simulatedTouchscreen));
        Assert.That(Touch.activeTouches[0].screenPosition, Is.EqualTo(new Vector2(123, 234)).Using(Vector2EqualityComparer.Instance));
        Assert.That(Touch.activeTouches[0].delta, Is.EqualTo(Vector2.zero).Using(Vector2EqualityComparer.Instance));
        Assert.That(Touch.activeTouches[0].phase, Is.EqualTo(TouchPhase.Began));
        Assert.That(Touch.activeTouches[0].tapCount, Is.EqualTo(0));
        Assert.That(Touch.activeTouches[0].isTap, Is.False);

        Move(pointer.position, new Vector2(234, 345));

        Assert.That(Touch.activeTouches, Has.Count.EqualTo(1));
        Assert.That(Touch.activeTouches[0].touchId, Is.EqualTo(1));
        Assert.That(Touch.activeTouches[0].screen, Is.SameAs(TouchSimulation.instance.simulatedTouchscreen));
        Assert.That(Touch.activeTouches[0].screenPosition, Is.EqualTo(new Vector2(234, 345)).Using(Vector2EqualityComparer.Instance));
        Assert.That(Touch.activeTouches[0].delta, Is.EqualTo(new Vector2(111, 111)).Using(Vector2EqualityComparer.Instance));
        Assert.That(Touch.activeTouches[0].phase, Is.EqualTo(TouchPhase.Moved));
        Assert.That(Touch.activeTouches[0].tapCount, Is.EqualTo(0));
        Assert.That(Touch.activeTouches[0].isTap, Is.False);

        Release(pointer.press);

        Assert.That(Touch.activeTouches, Has.Count.EqualTo(1));
        Assert.That(Touch.activeTouches[0].touchId, Is.EqualTo(1));
        Assert.That(Touch.activeTouches[0].screen, Is.SameAs(TouchSimulation.instance.simulatedTouchscreen));
        Assert.That(Touch.activeTouches[0].screenPosition, Is.EqualTo(new Vector2(234, 345)).Using(Vector2EqualityComparer.Instance));
        Assert.That(Touch.activeTouches[0].delta, Is.EqualTo(Vector2.zero).Using(Vector2EqualityComparer.Instance));
        Assert.That(Touch.activeTouches[0].phase, Is.EqualTo(TouchPhase.Ended));
        Assert.That(Touch.activeTouches[0].tapCount, Is.EqualTo(0));
        Assert.That(Touch.activeTouches[0].isTap, Is.False);

        PressAndRelease(pointer.press);

        Assert.That(Touch.activeTouches, Has.Count.EqualTo(1));
        Assert.That(Touch.activeTouches[0].touchId, Is.EqualTo(2));
        Assert.That(Touch.activeTouches[0].screen, Is.SameAs(TouchSimulation.instance.simulatedTouchscreen));
        Assert.That(Touch.activeTouches[0].screenPosition, Is.EqualTo(new Vector2(234, 345)).Using(Vector2EqualityComparer.Instance));
        Assert.That(Touch.activeTouches[0].delta, Is.EqualTo(Vector2.zero).Using(Vector2EqualityComparer.Instance));
        Assert.That(Touch.activeTouches[0].phase, Is.EqualTo(TouchPhase.Ended));
        Assert.That(Touch.activeTouches[0].tapCount, Is.EqualTo(1));
        Assert.That(Touch.activeTouches[0].isTap, Is.True);

        PressAndRelease(pointer.press);

        Assert.That(Touch.activeTouches, Has.Count.EqualTo(1));
        Assert.That(Touch.activeTouches[0].touchId, Is.EqualTo(3));
        Assert.That(Touch.activeTouches[0].screen, Is.SameAs(TouchSimulation.instance.simulatedTouchscreen));
        Assert.That(Touch.activeTouches[0].screenPosition, Is.EqualTo(new Vector2(234, 345)).Using(Vector2EqualityComparer.Instance));
        Assert.That(Touch.activeTouches[0].delta, Is.EqualTo(Vector2.zero).Using(Vector2EqualityComparer.Instance));
        Assert.That(Touch.activeTouches[0].phase, Is.EqualTo(TouchPhase.Ended));
        Assert.That(Touch.activeTouches[0].tapCount, Is.EqualTo(2));
        Assert.That(Touch.activeTouches[0].isTap, Is.True);
    }
 private void OnEnable()
 {
     inputs.BatMap.Enable();
     TouchSimulation.Enable();
 }
Esempio n. 6
0
 private void Start()
 {
     TouchSimulation.Enable();
 }
 /// <summary>
 /// Runs on enable of the class this gameobject is attached to.
 /// </summary>
 protected void OnEnable()
 {
     EnhancedTouchSupport.Enable();
     TouchSimulation.Enable();
 }