Example #1
0
    public void EnhancedTouch_CanSimulateTouchInputFromMultiplePointers()
    {
        var pointer1 = InputSystem.AddDevice <Pointer>();
        var pointer2 = InputSystem.AddDevice <Pointer>();

        TouchSimulation.Enable();

        Set(pointer1.position, new Vector2(123, 234), queueEventOnly: true);
        Set(pointer2.position, new Vector2(234, 345), queueEventOnly: true);
        Press(pointer1.press, queueEventOnly: true);
        Press(pointer2.press, queueEventOnly: true);

        InputSystem.Update();

        Assert.That(Touch.activeTouches, Has.Count.EqualTo(2));
        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[1].touchId, Is.EqualTo(2));
        Assert.That(Touch.activeTouches[1].screen, Is.SameAs(TouchSimulation.instance.simulatedTouchscreen));
        Assert.That(Touch.activeTouches[1].screenPosition, Is.EqualTo(new Vector2(234, 345)).Using(Vector2EqualityComparer.Instance));
        Assert.That(Touch.activeTouches[1].delta, Is.EqualTo(Vector2.zero).Using(Vector2EqualityComparer.Instance));
        Assert.That(Touch.activeTouches[1].phase, Is.EqualTo(TouchPhase.Began));
    }
Example #2
0
    public void EnhancedTouch_TouchSimulation_ProducesOneTouchFromEveryNonSyntheticButton()
    {
        const string json = @"
            {
                ""name"" : ""CustomPointer"",
                ""extend"" : ""Pointer"",
                ""controls"" : [
                    { ""name"" : ""syntheticButton"", ""layout"" : ""Button"", ""synthetic"" : true },
                    { ""name"" : ""nonSyntheticButton"", ""layout"" : ""Button"" }
                ]
            }
        ";

        InputSystem.RegisterLayout(json);
        var device = (Pointer)InputSystem.AddDevice("CustomPointer");

        TouchSimulation.Enable();

        Press((ButtonControl)device["nonSyntheticButton"]);

        Assert.That(Touch.activeTouches, Has.Count.EqualTo(1));
        Assert.That(Touch.activeTouches[0].touchId, Is.EqualTo(1));

        Press((ButtonControl)device["syntheticButton"]);

        Assert.That(Touch.activeTouches, Has.Count.EqualTo(1));
        Assert.That(Touch.activeTouches[0].touchId, Is.EqualTo(1));
    }
Example #3
0
    public void EnhancedTouch_TouchSimulation_ReusesSimulatedTouchscreenInstanceIfPresent()
    {
        var device = InputSystem.AddDevice <Touchscreen>("Simulated Touchscreen");

        TouchSimulation.Enable();

        Assert.That(TouchSimulation.instance.simulatedTouchscreen, Is.SameAs(device));
    }
Example #4
0
 private void Start()
 {
     EnhancedTouchSupport.Enable();
     TouchSimulation.Enable();
     Debug.Log("TouchSimulation Enabled!");
     cam = transform.GetChild(0).GetComponent <Camera>();
     UnityEngine.InputSystem.EnhancedTouch.Touch.onFingerDown += OnFingerDown;
     UnityEngine.InputSystem.EnhancedTouch.Touch.onFingerUp   += OnFingerUp;
 }
Example #5
0
    private void OnDisable()
    {
#if UNITY_EDITOR
        TouchSimulation.Disable();
#endif
        if (touchControls == null)
        {
            return;
        }

        touchControls.Disable();
        touchControls.Touch.TouchPress.started  -= On_TouchPressStarted;
        touchControls.Touch.TouchPress.canceled -= On_TouchPressCanceled;
    }
Example #6
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);
    }
Example #7
0
    public override void Setup()
    {
        base.Setup();

        // Disable() will not reset this so default initialize it here.
        Touch.s_HistoryLengthPerFinger = 64;

        if (!TestContext.CurrentContext.Test.Properties.ContainsKey("EnhancedTouchDisabled"))
        {
            InputSystem.AddDevice <Touchscreen>();
            EnhancedTouchSupport.Enable();
        }

        // Make sure we don't run into interference with a TouchSimulation instance that may
        // already be in place.
        m_OldTouchSimulationInstance = TouchSimulation.s_Instance;
        TouchSimulation.s_Instance   = null;
    }
Example #8
0
    public override void TearDown()
    {
        EnhancedTouchSupport.Disable();

        // Make sure cleanup really did clean up.
        Assert.That(Touch.s_Touchscreens.length, Is.EqualTo(0));
        Assert.That(Touch.s_PlayerState, Is.EqualTo(default(Touch.FingerAndTouchState)));
        #if UNITY_EDITOR
        Assert.That(Touch.s_EditorState, Is.EqualTo(default(Touch.FingerAndTouchState)));
        #endif

        // Some state is kept alive in-between Disable/Enable. Manually clean it out.
        Touch.s_OnFingerDown = new InlinedArray <Action <Finger> >();
        Touch.s_OnFingerUp   = new InlinedArray <Action <Finger> >();
        Touch.s_OnFingerMove = new InlinedArray <Action <Finger> >();

        TouchSimulation.Destroy();
        TouchSimulation.s_Instance   = m_OldTouchSimulationInstance;
        m_OldTouchSimulationInstance = null;

        base.TearDown();
    }
Example #9
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));
    }
Example #10
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);
    }
Example #11
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();
 }
Example #13
0
 private void Start()
 {
     TouchSimulation.Enable();
 }
 /// <summary>
 /// Disables when invoked or closed.
 /// </summary>
 protected void OnDisable()
 {
     EnhancedTouchSupport.Disable();
     TouchSimulation.Disable();
 }
 /// <summary>
 /// Runs on enable of the class this gameobject is attached to.
 /// </summary>
 protected void OnEnable()
 {
     EnhancedTouchSupport.Enable();
     TouchSimulation.Enable();
 }