private void onPointerButtonInputDown(PointerButtonInputEventArgs args)
 {
     fetchCurrentPointerInput();
     _pointerInputsOnClickStart[0] = _pointerInputRegistry.GetPointerInput(0);
     _pointerInputsOnClickStart[1] = _pointerInputRegistry.GetPointerInput(1);
     OnPinchStart?.Invoke(new PinchInputEventArgs(PinchState.Start, calculateAxis(), 0, _pointerInputsOnClickStart, 0));
 }
        public void SetCurrentState(TouchInputState state)
        {
            switch (_CurrentState)
            {
            case TouchInputState.TAPPING:
                break;

            case TouchInputState.DRAGGING:
                OnDragStop?.Invoke();
                break;

            case TouchInputState.PINCHING:
                OnPinchStop?.Invoke();
                break;
            }

            switch (state)
            {
            case TouchInputState.TAPPING:
                break;

            case TouchInputState.DRAGGING:
                OnDragStart?.Invoke();
                break;

            case TouchInputState.PINCHING:
                OnPinchStart?.Invoke();
                break;
            }

            _CurrentState = state;
        }
Example #3
0
 private void StartPinch()
 {
     PinchStartPositions[0] = TouchWrapper.Touches[0].Position;
     PinchStartPositions[1] = TouchWrapper.Touches[1].Position;
     pinchStartDistance     = GetPinchDistance(PinchStartPositions[0], PinchStartPositions[1]);
     if (OnPinchStart != null)
     {
         OnPinchStart.Invoke((PinchStartPositions[0] + PinchStartPositions[1]) * 0.5f, pinchStartDistance);
     }
     isClickPrevented = true;
 }
        private void StartPinch()
        {
            pinchStartPositions[0] = touchPositionLastFrame[0] = TouchWrapper.Touches[0].Position;
            pinchStartPositions[1] = touchPositionLastFrame[1] = TouchWrapper.Touches[1].Position;

            pinchStartDistance = GetPinchDistance(pinchStartPositions[0], pinchStartPositions[1]);
            if (OnPinchStart != null)
            {
                OnPinchStart.Invoke((pinchStartPositions[0] + pinchStartPositions[1]) * 0.5f, pinchStartDistance);
            }
            isClickPrevented         = true;
            pinchRotationVectorStart = TouchWrapper.Touches[1].Position - TouchWrapper.Touches[0].Position;
            pinchVectorLastFrame     = pinchRotationVectorStart;
            totalFingerMovement      = 0;
        }
Example #5
0
        private void UpdateTouches()
        {
            if (input == null || input.TouchCount() == 0)
            {
                return;
            }
            if (input.TouchCount() == 1)
            {
                TouchInfo touchInfo = input.GetTouch(0);
                if (currentTouch.GestureType == GestureType.None)
                {
                    actionStartTime = Time.realtimeSinceStartup;
                }
                touchInfo.StartTime = actionStartTime;
                if (touchInfo.Phase == TouchPhase.Began)
                {
                    Touch touch = new Touch
                    {
                        TouchInfo      = touchInfo,
                        GestureType    = GestureType.None,
                        SwipeDirection = SwipeDirection.None,
                        SwipeLength    = 0,
                        SwipeVector    = Vector2.zero
                    };
                    currentTouch = touch;
                    OnTouchStart?.Invoke(touch);
                }
                if (touchInfo.Phase == TouchPhase.Moved)
                {
                    OnTouch?.Invoke(new Touch
                    {
                        TouchInfo   = touchInfo,
                        GestureType = GestureType.None,
                    });
                    if (touchInfo.PositionDelta.magnitude >= settings.GetSwipeLengthInPixels())
                    {
                        Touch touch = new Touch
                        {
                            TouchInfo      = touchInfo,
                            GestureType    = GestureType.Swipe,
                            SwipeDirection = GetSwipeDirection(touchInfo.Position - touchInfo.PositionDelta, touchInfo.Position),
                            SwipeLength    = touchInfo.PositionDelta.magnitude,
                            SwipeVector    = touchInfo.PositionDelta
                        };
                        switch (currentTouch.GestureType)
                        {
                        case GestureType.None:
                            OnSwipeStart?.Invoke(touch);
                            break;

                        case GestureType.Swipe:
                            OnSwipe?.Invoke(touch);
                            break;
                        }
                        currentTouch = touch;
                        return;
                    }
                }

                if (touchInfo.Phase == TouchPhase.Stationary)
                {
                    OnTouch?.Invoke(new Touch
                    {
                        TouchInfo   = touchInfo,
                        GestureType = GestureType.None,
                    });
                    touchInfo.ActionTime = Time.realtimeSinceStartup - touchInfo.StartTime;
                    currentTouch         = new Touch
                    {
                        TouchInfo      = touchInfo,
                        GestureType    = GestureType.Tap,
                        SwipeDirection = SwipeDirection.None,
                        SwipeLength    = 0,
                        SwipeVector    = Vector2.zero
                    };
                }
                if (touchInfo.Phase == TouchPhase.Ended)
                {
                    OnTouchEnd?.Invoke(new Touch
                    {
                        TouchInfo   = touchInfo,
                        GestureType = GestureType.None,
                    });
                    switch (currentTouch.GestureType)
                    {
                    case GestureType.Swipe:
                        OnSwipeEnd?.Invoke(currentTouch);
                        break;

                    case GestureType.Tap when currentTouch.TouchInfo.ActionTime <= settings.TapTime:
                        OnTap?.Invoke(currentTouch);
                        break;
                    }
                }
            }
            if (input.TouchCount() == 2)
            {
                TouchInfo touch0 = input.GetTouch(0);
                TouchInfo touch1 = input.GetTouch(1);
                if (currentTouch.GestureType == GestureType.None)
                {
                    actionStartTime = Time.realtimeSinceStartup;
                }
                touch0.StartTime = actionStartTime;
                if (touch0.Phase == TouchPhase.Began || touch1.Phase == TouchPhase.Began)
                {
                    Pinch pinch = new Pinch
                    {
                        TouchInfos  = new [] { touch0, touch1 },
                        GestureType = GestureType.None,
                        PinchVector = touch0.Position - touch1.Position
                    };
                    currentPinch = pinch;
                    OnPinchStart?.Invoke(currentPinch);
                }
                if (touch0.Phase != TouchPhase.Stationary ||
                    touch0.Phase == TouchPhase.Moved ||
                    touch1.Phase != TouchPhase.Stationary ||
                    touch1.Phase == TouchPhase.Moved)
                {
                    Pinch pinch = new Pinch
                    {
                        TouchInfos  = new [] { touch0, touch1 },
                        GestureType = GestureType.Pinch,
                        PinchVector = touch0.Position - touch1.Position
                    };
                    currentPinch = pinch;
                    OnPinch?.Invoke(currentPinch);
                }
                if (touch0.Phase == TouchPhase.Ended || touch1.Phase == TouchPhase.Ended)
                {
                    Pinch pinch = new Pinch
                    {
                        TouchInfos  = new [] { touch0, touch1 },
                        GestureType = GestureType.Pinch,
                        PinchVector = touch0.Position - touch1.Position
                    };
                    currentPinch = pinch;
                    OnPinchEnd?.Invoke(currentPinch);
                }
            }
        }