示例#1
0
    void GetSwipe(SwipeInfo info)
    {
        pivotObj.transform.rotation = defaultRot;
        float length = Vector2.Distance(info.SwipeStartPos, info.SwipeEndPos);

        if (info.isEnd || length < lastLength || (lastLength != 0 && lastSwipeDir != info.SwipeDirection))
        {
            defaultRot = pivotObj.transform.rotation;
            lastLength = 0;
        }
        else
        {
            lastLength = length;
        }

        lastSwipeDir = info.SwipeDirection;

        float multiplier = 1f;

        if (Vector2.SignedAngle(info.SwipeStartPos - centre, info.SwipeEndPos - centre) < 0)
        {
            multiplier *= -1;
        }

        pivotObj.transform.Rotate(Vector3.forward, length * rotationSpeed * multiplier);
    }
示例#2
0
 public Input_WI_OnSwipe(int fingerIndex, Vector2 fingerPos, ESwipeDirection swipeDirection, float velocity)
 {
     FingerIndex    = fingerIndex;
     FingerPos      = fingerPos;
     SwipeDirection = swipeDirection;
     Velocity       = velocity;
 }
示例#3
0
        private bool DetectDotDirectionSingleAxis(Vector2 normalizedDirection, Vector2 test, ESwipeDirection testEnum, ESwipeDirection oppositeEnum)
        {
            float dot = Vector2.Dot(test, normalizedDirection);

            // if 0, then it's either left or right. The normalized direction
            // will exactly equal the Vector2.right or Vector2.left ( in the right left case)
            if (dot == 0)
            {
                if (normalizedDirection == test)
                {
                    _currentDetectedDirection = testEnum;
                }
                else
                {
                    _currentDetectedDirection = oppositeEnum;
                }
                return(true);
            }

            // if it isn't 0, then work out which direction it is using the const dot
            if (dot <= 1 && dot >= cNormalizedDot45Degress)
            {
                _currentDetectedDirection = testEnum;
                return(true);
            }
            else if (dot >= -1 && dot <= -cNormalizedDot45Degress)
            {
                _currentDetectedDirection = oppositeEnum;
                return(true);
            }

            return(false);
        }
示例#4
0
 protected void FireOnRightSwipe(int fingerIndex, Vector2 fingerPos, ESwipeDirection swipeDirection, float swipeDelta)
 {
     if (OnRightSwipe != null)
     {
         OnRightSwipe(new Input_WI_OnRightSwipe(fingerIndex, fingerPos, swipeDirection, swipeDelta));
     }
 }
示例#5
0
        private void OnEventSwipe(ESwipeDirection aDirection)
        {
            EventHandler <EventArgsSwipe> del = EventSwipe;

            if (del != null)
            {
                del(this, new EventArgsSwipe(aDirection));
            }
        }
    // Once the swipe has been detected and it's ready, send the data.
    // The data sent is retrieved by the registered delegates.
    private void SendSwipeData(ESwipeDirection dir, bool hasEnded)
    {
        SwipeInfo swipeInfo = new SwipeInfo()
        {
            SwipeDirection = dir,
            SwipeStartPos  = m_touchDownPos,
            SwipeEndPos    = m_touchUpPos,
            isEnd          = hasEnded
        };

        OnSwipe(swipeInfo);
    }
        /// <summary>
        /// Updates the current swipe gesture for the frame. Must stop touching the trackpad to complete the gesture.
        /// </summary>
        private void UpdateSwipeState()
        {
            if (_trackedDevice.GetButtonUp(StylusButton.TouchstripTouch))
            {
                if ((Time.time - _touchStartTime) <= _timeToSwipeGesture)
                {
                    _swipeState = GetSwipeDirection(_initialTouchMoveDistance);
                    return;
                }
            }

            _swipeState = ESwipeDirection.None;
        }
    /*
     * Set swipe direction based on y and x values of end - start.
     */
    private void DetectSwipe(bool isEnd = false)
    {
        if (VertDist() > m_minSwipeThreshold || HorDist() > m_minSwipeThreshold)
        {
            if (IsVertSwipe())
            {
                ESwipeDirection dir = m_touchDownPos.y - m_touchUpPos.y > 0 ? ESwipeDirection.Swipe_Down : ESwipeDirection.Swipe_UP;
                SendSwipeData(dir, isEnd);
            }
            else
            {
                ESwipeDirection dir = m_touchDownPos.x - m_touchUpPos.x > 0 ? ESwipeDirection.Swipe_Left : ESwipeDirection.Swipe_Right;
                SendSwipeData(dir, isEnd);
            }

            m_touchUpPos = m_touchDownPos;
        }
    }
        void TryRecognize()
        {
            List <ESwipeDirection> detectedSwipes = new List <ESwipeDirection>();

            // For now, super basic!
            for (int i = 0; i < 2; i++)
            {
                LinkedList <Vector3> listOfInterest = i == 0 ? PrevLeftHandPositions : PrevRightHandPositions;
                if (listOfInterest.Count >= 3)
                {
                    // Need AT LEAST 3 positions
                    Vector2 start = listOfInterest.First.Value;
                    Vector2 end   = listOfInterest.Last.Value;
                    Vector2 diff  = end - start;
                    if (diff.x > WorldUnitsForHorizontalSwipe)
                    {
                        // Swipe right!
                        detectedSwipes.Add(ESwipeDirection.RIGHT);
                    }
                    else if (diff.x < -WorldUnitsForHorizontalSwipe)
                    {
                        detectedSwipes.Add(ESwipeDirection.LEFT);
                    }
                }
            }
            // If multiple swipes detected, only send one of them, for now
            if (detectedSwipes.Count > 0)
            {
                ESwipeDirection selected = (ESwipeDirection)detectedSwipes.Select((esw) => (int)esw).Min();
                SendSwipeEvent(selected);

                // Clear out the current lists so we don't get confused
                PrevLeftHandPositions.Clear();
                PrevRightHandPositions.Clear();
                CurrentSwipeCooldown = 0.0f;
            }
        }
 /// <summary>
 /// Checks if the trackpad has been swiped in a direction.
 /// </summary>
 /// <param name="swipeDirection">The swipe direction to check against.</param>
 /// <returns>
 /// If the tracked has been swiped in the specified direction.
 /// </returns>
 public bool OnSwipe(ESwipeDirection swipeDirection)
 {
     Update();
     return(_swipeState == swipeDirection);
 }
示例#11
0
 public Input_WI_OnRightSwipe(int fingerIndex, Vector2 fingerPos, ESwipeDirection swipeDirection, float swipeDelta)
     : base(fingerIndex, fingerPos, swipeDirection, swipeDelta)
 {
 }
示例#12
0
 private void OnSwipeBegin(ESwipeDirection pDirection)
 {
     if (mTouchedBalloonObject != null && pDirection == ESwipeDirection.UP/* && mTouchedBalloon.Type == EBalloonType.LIFE*/
         && TouchService.CurrentTouchPosition.y > mTouchedBalloonObject.transform.position.y)
     {
         mIsJumpCommand = true;
     }
 }
示例#13
0
 public EventArgsSwipe(ESwipeDirection aDirection)
 {
     Direction = aDirection;
 }
示例#14
0
 public bool OnSwipe(ESwipeDirection swipeDirection)
 {
     return(_trackpad.OnSwipe(swipeDirection));
 }
示例#15
0
 public OnSwipeEventArgs(ESwipeDirection direction)
 {
     this.Direction = direction;
 }
示例#16
0
 void SendSwipeEvent(ESwipeDirection dir)
 {
     OnSwipe?.Invoke(this, new OnSwipeEventArgs(dir));
 }