Esempio n. 1
0
        public void CheckDragging_OneTouchMovedAndWasThenWasNotPreviouslyDragging_NoDraggingOccurredAndNoTouchPositionReturned()
        {
            var fingerId                 = Random.Range(0, 9);
            var unityInputService        = Substitute.For <IUnityInputService>();
            var androidInteractionMapper = new AndroidInteractionMapper(unityInputService);

            unityInputService.GetTouches().Returns(new[] {
                new Touch
                {
                    phase    = TouchPhase.Began,
                    fingerId = fingerId,
                }
            });
            var result = androidInteractionMapper.CheckDragging(out _);

            Assert.IsTrue(result);

            unityInputService.GetTouches().Returns(new Touch[0]);
            result = androidInteractionMapper.CheckDragging(out _);
            Assert.IsFalse(result);

            unityInputService.GetTouches().Returns(new[] {
                new Touch
                {
                    phase    = TouchPhase.Moved,
                    fingerId = fingerId,
                }
            });

            result = androidInteractionMapper.CheckDragging(out var resultTouchPosition);

            Assert.IsFalse(result);
            Assert.AreEqual(null, resultTouchPosition);
        }
Esempio n. 2
0
        public void CheckDragEnd_OneTouchCanceledAndWasPreviouslyDragging_DragEndOccurredAndTouchPositionReturned()
        {
            var fingerId                 = Random.Range(0, 9);
            var unityInputService        = Substitute.For <IUnityInputService>();
            var androidInteractionMapper = new AndroidInteractionMapper(unityInputService);

            unityInputService.GetTouches().Returns(new[] {
                new Touch
                {
                    phase    = TouchPhase.Began,
                    fingerId = fingerId,
                }
            });
            var result = androidInteractionMapper.CheckDragging(out _);

            Assert.IsTrue(result);

            var randomTouchPosition = new Vector3(Random.Range(0, 10), Random.Range(0, 10), 0);

            unityInputService.GetTouches().Returns(new[] {
                new Touch
                {
                    position = randomTouchPosition,
                    phase    = TouchPhase.Canceled,
                    fingerId = fingerId,
                }
            });

            result = androidInteractionMapper.CheckDragEnd(out var resultTouchPosition);

            Assert.IsTrue(result);
            Assert.AreEqual(randomTouchPosition, resultTouchPosition);
        }
Esempio n. 3
0
        public void CheckDragEnd_MultipleTouchesAndWasPreviouslyDragging_DragEndOccurredAndTouchPositionReturned()
        {
            var unityInputService        = Substitute.For <IUnityInputService>();
            var androidInteractionMapper = new AndroidInteractionMapper(unityInputService);

            unityInputService.GetTouches().Returns(new[] {
                new Touch
                {
                    fingerId = 1,
                    phase    = TouchPhase.Began,
                }
            });
            var result = androidInteractionMapper.CheckDragging(out _);

            Assert.IsTrue(result);

            var randomTouchPosition1 = new Vector3(Random.Range(0, 10), Random.Range(0, 10), 0);
            var randomTouchPosition2 = new Vector3(randomTouchPosition1.x + 1, randomTouchPosition1.y + 1, 0);

            unityInputService.GetTouches().Returns(new[] {
                new Touch
                {
                    position = randomTouchPosition2,
                    phase    = TouchPhase.Began,
                    fingerId = 2,
                },
                new Touch
                {
                    position = randomTouchPosition1,
                    phase    = TouchPhase.Stationary,
                    fingerId = 1,
                }
            });

            result = androidInteractionMapper.CheckDragEnd(out var resultTouchPosition);

            Assert.IsTrue(result);
            Assert.AreEqual(randomTouchPosition1, resultTouchPosition);
        }