Beispiel #1
0
    public void OnPointerUp(PointerEventData eventData)
    {
        Vector2 direction = eventData.position - startDragPos;

        if (Math.Abs(direction.x) < minDistanceForSwipe && Math.Abs(direction.y) < minDistanceForSwipe)
        {
            OnTap?.Invoke();
            return;
        }

        if (Math.Abs(direction.x) >= Math.Abs(direction.y))
        {
            if (startDragPos.x < eventData.position.x)
            {
                OnSwipeRight?.Invoke();
            }
            else
            {
                OnSwipeLeft?.Invoke();
            }
        }
        else
        {
            if (startDragPos.y < eventData.position.y)
            {
                OnSwipeUp?.Invoke();
            }
            else
            {
                OnSwipeDown?.Invoke();
            }
        }
        startDragPos = Vector2.zero;
    }
Beispiel #2
0
        private void Update()
        {
#if UNITY_ANDROID
            if (EventSystem.current.IsPointerOverGameObject(0))
            {
                return;
            }
#else
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }
#endif

            if (Input.GetMouseButtonDown(0))
            {
                Vector2 worldMousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                Collider2D tap = Physics2D.OverlapPoint(worldMousePosition);

                if (tap != null)
                {
                    OnTap?.Invoke();
                }
            }
        }
Beispiel #3
0
 public void OnPointerDown(PointerEventData eventData)
 {
     if (!blockTap)
     {
         OnTap?.Invoke();
     }
 }
Beispiel #4
0
 private void Update()
 {
     if (Input.touchCount > 0)
     {
         Touch touch = Input.GetTouch(0);
         if (touch.phase == TouchPhase.Began)
         {
             OnTap?.Invoke(mainCamera.ScreenToWorldPoint(touch.position));
         }
     }
 }
Beispiel #5
0
 public void OnTapScreen(InputAction.CallbackContext context)
 {
     if (EventSystem.current.IsPointerOverGameObject())
     {
         return;
     }
     if (context.started)
     {
         OnTap?.Invoke(this, EventArgs.Empty);
     }
 }
Beispiel #6
0
 void DoAction(Gesture gesture)
 {
     if (realType == GameObjectType.UI)
     {
         if (gesture.isOverGui)
         {
             if ((gesture.pickedUIElement == gameObject || gesture.pickedUIElement.transform.IsChildOf(transform)))
             {
                 onTap.Invoke(gesture);
             }
         }
     }
     else
     {
         if ((!enablePickOverUI && gesture.pickedUIElement == null) || enablePickOverUI)
         {
             if (EasyTouch.GetGameObjectAt(gesture.position, is2Finger) == gameObject)
             {
                 onTap.Invoke(gesture);
             }
         }
     }
 }
Beispiel #7
0
    private void FireTapEvent()
    {
        GameObject   hitObj = GetHitGameObject(startPos);
        TapEventArgs args   = new TapEventArgs(startPos, hitObj);

        OnTap?.Invoke(this, args);

        if (hitObj != null)
        {
            if (hitObj.TryGetComponent(out ITappable tappedObj))
            {
                tappedObj.OnTap();
            }
        }
    }
        private void AddBirdListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            string birdName = filteredMstrBirdList[e.Position].Name;    // Must use 'filtered Master' or picking the third item in the filtered list will actually add the third bird name in 'Master' list.

            if (wrkBirdList.Exists(x => x.Name == birdName))
            {
                string alert = "This bird already exists in your current list.";
                Toast.MakeText(this.Activity, alert, ToastLength.Short).Show();
            }
            else
            {
                OnTap.Invoke(this, new OnTapEventArgs(birdName));
                this.Dismiss();
            }
        }
Beispiel #9
0
        private void Update()
        {
            switch (tapped)
            {
            case false when Input.touchCount > 0:
                tapped = !tapped;
                OnTap?.Invoke();
                break;

            case true:
                MobileInput(out var moveDirection);
                movement.MoveDirection = moveDirection;
                break;
            }
        }
Beispiel #10
0
 /// <summary>
 /// Checks if player touched the game object check for shorter than <see cref="TOUCH_DRAG_DELAY"/> to trigger tap event,
 /// if user was touching the object for that amount of time and didn't move their finger for more than <see cref="TOUCH_DRAG_MAX_OFFSET"/> triggers drag and drop.
 /// </summary>
 void Update()
 {
     if (pointerDownCoroutine != null)
     {
         if (Input.touchCount > 0 && Vector2.Distance(Input.GetTouch(0).position, dragBeginPosition) > TOUCH_DRAG_MAX_OFFSET)
         {
             StopCoroutine(pointerDownCoroutine);
             pointerDownCoroutine = null;
         }
         else if (Input.touchCount == 0)
         {
             StopCoroutine(pointerDownCoroutine);
             pointerDownCoroutine = null;
             OnTap.Invoke();
         }
     }
 }
Beispiel #11
0
    private void FireTapEvent()
    {
        GameObject hitObj = GetHitInfo(startPoint);

        var args = new TapEventArgs(startPoint, hitObj);

        OnTap?.Invoke(this, args);

        if (hitObj is null)
        {
            return;
        }

        var tap = hitObj.GetComponent <ITapped>();

        tap.OnTap(args);
    }
Beispiel #12
0
 void Tap()
 {
     if (tapsCount == 0)
     {
         OnTap?.Invoke();
         tapsCount++;
     }
     else if (tapsCount == 1)
     {
         OnTap2?.Invoke();
         tapsCount++;
     }
     else if (tapsCount == 2 && Player.Player.normalVector == Vector2.left)
     {
         OnTap3?.Invoke();
     }
 }
Beispiel #13
0
        private void DetectTapGestures()
        {
            TouchManipulationInfo[] infos = new TouchManipulationInfo[_touchDictionary.Count];
            _touchDictionary.Values.CopyTo(infos, 0);
            if (infos.Length != 1)
            {
                return;
            }
            SKPoint point = infos[0].PreviousPoint;

            if (infos[0].MoveCounter > MaxTapMoveCounter)
            {
                return;
            }
            var tapEventArgs = new TapEventArgs(point);

            var now         = DateTime.Now;
            var lastTapTime = LastTapTime;

            LastTapTime = now;

            OnTap?.Invoke(this, tapEventArgs);
            if (now - lastTapTime < DoubleTapDelay)
            {
                OnDoubleTap?.Invoke(this, tapEventArgs);
                LastDoubleTapTime = now;
                LastTapTime       = DateTime.MinValue; //Reset double tap timer
            }
            else
            {
                _timer = new Timer(_ =>
                {
                    if (DateTime.Now - LastDoubleTapTime < DoubleTapDelay)
                    {
                        return;
                    }
                    OnSingleTap?.Invoke(this, tapEventArgs);
                }, null, DoubleTapDelay.Milliseconds, Timeout.Infinite);
            }
        }
        private void HandleTapping()
        {
            Touch[] touches = Input.touches;
            for (int i = 0; i < touches.Length; i++)
            {
                if (touches[i].phase != TouchPhase.Ended)
                {
                    continue;
                }
                OnTap?.Invoke();

                if (!ShootGraphicsRays(Input.mousePosition))
                {
                    if (!ShootPhysicsRay(touches[i].position))
                    {
                        OnDeselect?.Invoke();
                    }
                }
            }

            if (touches.Length == 1)
            {
                if (touches[0].deltaPosition.magnitude > _DragThreshold)
                {
                    SetCurrentState(TouchInputState.DRAGGING);
                }
            }

            if (touches.Length == 2)
            {
                float delta = InputUtils.GetTouchDistanceDelta(touches[0], touches[1]);

                if (Mathf.Abs(delta) > _PinchThreshold)
                {
                    SetCurrentState(TouchInputState.PINCHING);
                }
            }
        }
        private void HandleDebugMouse()
        {
#if UNITY_EDITOR
            if (Input.GetMouseButtonDown(1))
            {
                _PreviousMousePosition = Input.mousePosition;
                OnDragStart?.Invoke();
            }

            if (Input.GetMouseButton(1))
            {
                Vector2 mousePos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                OnDragDelta?.Invoke((mousePos - _PreviousMousePosition) * 2);
                _PreviousMousePosition = Input.mousePosition;
            }

            if (Input.GetMouseButtonUp(1))
            {
                OnDragStop?.Invoke();
            }

            OnPinchDelta?.Invoke(Input.mouseScrollDelta.y * 45);

            if (Input.GetMouseButtonDown(0))
            {
                OnTap?.Invoke();

                if (!ShootGraphicsRays(Input.mousePosition))
                {
                    if (!ShootPhysicsRay(Input.mousePosition))
                    {
                        OnDeselect?.Invoke();
                    }
                }
            }
#endif
        }
Beispiel #16
0
 public void Tap()
 {
     OnTap?.Invoke(_score);
     ReturnToPool();
 }
Beispiel #17
0
 private void TapRecognizer_Tapped(object sender, EventArgs e)
 {
     OnTap?.Invoke(this, e);
 }
        public override bool OnSingleTapUp(MotionEvent e)
        {
            OnTap?.Invoke(this, null);

            return(base.OnSingleTapUp(e));
        }
Beispiel #19
0
        public void Update(GameTime gameTime)
        {
            touchCollection = TouchPanel.GetState();
            while (TouchPanel.IsGestureAvailable)
            {
                gesture = TouchPanel.ReadGesture();
                switch (gesture.GestureType)
                {
                case GestureType.Flick:
                {
                    if (gesture.Delta.X > 0 && gesture.Delta.Y > 0)        //topright
                    {
                        if (gesture.Delta.X < gesture.Delta.Y)
                        {
                            OnFlickDown?.Invoke(gesture, null);
                        }
                        else
                        {
                            OnFlickRight?.Invoke(gesture, null);
                        }
                    }
                    else if (gesture.Delta.X > 0 && gesture.Delta.Y < 0)        //bottomright
                    {
                        if (gesture.Delta.X < -gesture.Delta.Y)
                        {
                            OnFlickUp?.Invoke(gesture, null);
                        }
                        else
                        {
                            OnFlickRight?.Invoke(gesture, null);
                        }
                    }
                    else if (gesture.Delta.X < 0 && gesture.Delta.Y < 0)        //bottomleft
                    {
                        if (-gesture.Delta.X < -gesture.Delta.Y)
                        {
                            OnFlickUp?.Invoke(gesture, null);
                        }
                        else
                        {
                            OnFlickLeft?.Invoke(gesture, null);
                        }
                    }
                    else if (gesture.Delta.X < 0 && gesture.Delta.Y > 0)        //topleft
                    {
                        if (-gesture.Delta.X < gesture.Delta.Y)
                        {
                            OnFlickDown?.Invoke(gesture, null);
                        }
                        else
                        {
                            OnFlickLeft?.Invoke(gesture, null);
                        }
                    }
                    break;
                }

                case GestureType.Tap:
                {
                    if (ScaledResolution != Vector2.Zero)
                    {
                        OnTap?.Invoke(new Vector2(gesture.Position.X / TouchPanel.DisplayWidth * ScaledResolution.X, gesture.Position.Y / TouchPanel.DisplayHeight * ScaledResolution.Y), null);
                    }

                    break;
                }
                }
            }
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                OnBackButtonClicked?.Invoke(this, null);
            }
        }
Beispiel #20
0
        public void Tap()
        {
            //Debug.Log("tapped");

            onTap?.Invoke();
        }
Beispiel #21
0
        protected bool Init()
        {
            OnTouchBegan = (touch, cCEvent) =>
            {
                if (_isTouched)
                {
                    return(false);
                }

                _isTouched      = true;
                _touchStartTime = DateTime.Now;
                _touchStartPos  = touch.Location;
                _touchNowPos    = touch.Location;

                //                    this
                //                    CCScheduler
                //Director::getInstance()->getScheduler()->schedule(schedule_selector(EventListenerGesture::_updateInTouch), this, 0.05f, false);
                return(true);
            };
            this.
            OnTouchCancelled = (_touch, ccEvent) =>
            {
                _isTouched   = false;
                _gestureType = GestureType.NONE;
            };

            OnTouchMoved = (touch, ccEvent) =>
            {
                //if (_gestureType != GestureType.NONE)
                //{
                //    return;
                //}

                _touchNowPos = touch.Location;
                var xDiff          = _touchNowPos.X - _touchStartPos.X;
                var xDiffAbs       = Math.Abs((int)(xDiff));
                var yDiff          = _touchNowPos.Y - _touchStartPos.Y;
                var yDiffAbs       = Math.Abs((int)(yDiff));
                var swipeDirection = SwipeDirection.NONE;

                if (xDiffAbs >= yDiffAbs)
                {
                    if (xDiffAbs > _swipeThresholdDistance)
                    {
                        swipeDirection = xDiff >= 0 ? SwipeDirection.RIGHT : SwipeDirection.LEFT;
                    }
                }
                else
                {
                    if (yDiffAbs > _swipeThresholdDistance)
                    {
                        swipeDirection = yDiff >= 0 ? SwipeDirection.UP : SwipeDirection.DOWN;
                    }
                }

                if (swipeDirection != SwipeDirection.NONE)
                {
                    _gestureType = GestureType.SWIPE;
                    OnSwipeing?.Invoke(swipeDirection);
                }
                _swipeDirection = swipeDirection;
            };

            OnTouchEnded = (touch, ccEvent) =>
            {
                if (_gestureType == GestureType.SWIPE)
                {
                    OnSwipeEnded?.Invoke(_swipeDirection);
                    _swipeDirection = SwipeDirection.NONE;
                }
                else
                if (_gestureType == GestureType.NONE)
                {
                    OnTap?.Invoke(touch.Delta);
                }
                else if (_gestureType == GestureType.LONG_TAP)
                {
                    OnLongTapEnded.Invoke(touch.Delta);
                }

                //Director::getInstance()->getScheduler()->
                //    unschedule(schedule_selector(EventListenerGesture::_updateInTouch), this);
                _gestureType = GestureType.NONE;
                _isTouched   = false;
            };

            return(true);
        }
Beispiel #22
0
 private void LeanTouch_OnFingerTap(LeanFinger finger)
 {
     OnTap?.Invoke(finger.GetWorldPosition(10f));
 }
Beispiel #23
0
    public void DoUpdate()
    {
        if (Input.touchCount == 1)         // user is touching the screen with a single touch
        {
            var touch = Input.GetTouch(0); // get the touch
            switch (touch.phase)
            {
            //check for the first touch
            case TouchPhase.Began:
                _fp = touch.position;
                _lp = touch.position;
                break;

            // update the last position based on where they moved
            case TouchPhase.Moved:
                _lp = touch.position;
                break;

            //check if the finger is removed from the screen
            case TouchPhase.Ended:
            {
                _lp = touch.position;                         //last touch position. Ommitted if you use list

                //Check if drag distance is greater than 20% of the screen height
                if (Mathf.Abs(_lp.x - _fp.x) > _dragDistance || Mathf.Abs(_lp.y - _fp.y) > _dragDistance)
                {
                    //It's a drag
                    //check if the drag is vertical or horizontal
                    if (Mathf.Abs(_lp.x - _fp.x) > Mathf.Abs(_lp.y - _fp.y))
                    {
                        //If the horizontal movement is greater than the vertical movement...
                        if ((_lp.x > _fp.x))                                 //If the movement was to the right)
                        {
                            //Right swipe
                            OnSwipeRight?.Invoke();
                        }
                        else
                        {
                            OnSwipeLeft?.Invoke();
                            //Left swipe
                        }
                    }
                    else
                    {
                        //the vertical movement is greater than the horizontal movement
                        if (_lp.y > _fp.y)                                 //If the movement was up
                        {
                            //Up swipe
                            OnSwipeUP?.Invoke();
                        }
                        else
                        {
                            OnSwipeDown?.Invoke();
                            //Down swipe
                        }
                    }
                }
                else
                {
                    OnTap?.Invoke();
                    //It's a tap as the drag distance is less than 20% of the screen height
                    Debug.Log("Tap");
                }

                break;
            }
            }
        }
    }
Beispiel #24
0
 private void Tap(InputAction.CallbackContext ctx)
 {
     OnTap?.Invoke();
 }
Beispiel #25
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);
                }
            }
        }