コード例 #1
0
        protected virtual void Update()
        {
            // Get fingers
            var fingers = Use.GetFingers();

            if (fingers.Count > 1 && onPinch != null)
            {
                switch (Coordinate)
                {
                case CoordinateType.OneBasedScale:
                {
                    var scale = LeanGesture.GetPinchScale(fingers);

                    scale = Mathf.Pow(scale, Multiplier);

                    onPinch.Invoke(scale);
                }
                break;

                case CoordinateType.OneBasedRatio:
                {
                    var ratio = LeanGesture.GetPinchRatio(fingers);

                    ratio = Mathf.Pow(ratio, Multiplier);

                    onPinch.Invoke(ratio);
                }
                break;

                case CoordinateType.ZeroBasedScale:
                {
                    var scale = LeanGesture.GetPinchScale(fingers);

                    scale = (scale - 1.0f) * Multiplier;

                    onPinch.Invoke(scale);
                }
                break;

                case CoordinateType.ZeroBasedRatio:
                {
                    var ratio = LeanGesture.GetPinchRatio(fingers);

                    ratio = (ratio - 1.0f) * Multiplier;

                    onPinch.Invoke(ratio);
                }
                break;

                case CoordinateType.ZeroBasedDistance:
                {
                    var oldDistance = LeanGesture.GetLastScaledDistance(fingers, LeanGesture.GetLastScreenCenter(fingers));
                    var newDistance = LeanGesture.GetScaledDistance(fingers, LeanGesture.GetScreenCenter(fingers));
                    var movement    = (newDistance - oldDistance) * Multiplier;

                    onPinch.Invoke(movement);
                }
                break;
                }
            }
        }
コード例 #2
0
        private void FingerSwipe(List <LeanFinger> fingers, LeanFinger swipedFinger)
        {
            var scaledDelta = swipedFinger.SwipeScaledDelta;
            var isParallel  = true;

            swiped = true;

            // Go through all fingers
            for (var i = fingers.Count - 1; i >= 0; i--)
            {
                var finger = fingers[i];

                // If it's too old to swipe, skip
                if (finger.Age > LeanTouch.CurrentTapThreshold)
                {
                    return;
                }

                // If it didn't move far enough to swipe, skip
                if (finger.SwipeScaledDelta.magnitude < ScaledDistanceThreshold)
                {
                    return;
                }

                // If the finger didn't move parallel the others, make the OnSwipeParallel event inelligible
                if (finger != swipedFinger)
                {
                    var angle = Vector2.Angle(scaledDelta, finger.SwipeScaledDelta);

                    if (angle > ParallelAngleThreshold)
                    {
                        isParallel = false;
                    }
                }
            }

            if (onFingers != null)
            {
                onFingers.Invoke(fingers);
            }

            if (fingers.Count > 1)
            {
                var centerA = LeanGesture.GetStartScreenCenter(fingers);
                var centerB = LeanGesture.GetScreenCenter(fingers);

                if (onSwipeParallel != null && isParallel == true)
                {
                    var delta = centerA - centerB;

                    onSwipeParallel.Invoke(delta * LeanTouch.ScalingFactor);
                }
                else
                {
                    var pinch = LeanGesture.GetScaledDistance(fingers, centerB) - LeanGesture.GetStartScaledDistance(fingers, centerA);

                    if (onSwipeIn != null && pinch <= -PinchScaledDistanceThreshold)
                    {
                        onSwipeIn.Invoke(-pinch);
                    }

                    if (onSwipeOut != null && pinch >= PinchScaledDistanceThreshold)
                    {
                        onSwipeOut.Invoke(pinch);
                    }
                }
            }
        }
コード例 #3
0
        private void FingerSwipe(LeanFinger swipedFinger)
        {
            // Prevent multi invocation
            if (swiped == false)
            {
                // Get all valid fingers for swipe
                var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, false, RequiredFingerCount, RequiredSelectable);

                // Make sure there are some fingers, and the current finger is a part of it
                if (fingers.Count > 0 && fingers.Contains(swipedFinger) == true)
                {
                    swiped = true;

                    var scaledDelta = swipedFinger.SwipeScaledDelta;
                    var isParallel  = true;

                    // Go through all fingers
                    for (var i = fingers.Count - 1; i >= 0; i--)
                    {
                        var finger = fingers[i];

                        // If it's too old to swipe, skip
                        if (finger.Age > LeanTouch.CurrentTapThreshold)
                        {
                            return;
                        }

                        // If it didn't move far enough to swipe, skip
                        if (finger.SwipeScaledDelta.magnitude < ScaledDistanceThreshold)
                        {
                            return;
                        }

                        // If the finger didn't move parallel the others, make the OnSwipeParallel event inelligible
                        if (finger != swipedFinger)
                        {
                            var angle = Vector2.Angle(scaledDelta, finger.SwipeScaledDelta);

                            if (angle > ParallelAngleThreshold)
                            {
                                isParallel = false;
                            }
                        }
                    }

                    if (OnSwipe != null)
                    {
                        OnSwipe.Invoke(fingers);
                    }

                    if (fingers.Count > 1)
                    {
                        var centerA = LeanGesture.GetStartScreenCenter(fingers);
                        var centerB = LeanGesture.GetScreenCenter(fingers);

                        if (OnSwipeParallel != null && isParallel == true)
                        {
                            var delta = centerA - centerB;

                            OnSwipeParallel.Invoke(delta * LeanTouch.ScalingFactor);
                        }
                        else
                        {
                            var pinch = LeanGesture.GetScaledDistance(fingers, centerB) - LeanGesture.GetStartScaledDistance(fingers, centerA);

                            if (OnSwipeIn != null && pinch <= -PinchScaledDistanceThreshold)
                            {
                                OnSwipeIn.Invoke(-pinch);
                            }

                            if (OnSwipeOut != null && pinch >= PinchScaledDistanceThreshold)
                            {
                                OnSwipeOut.Invoke(pinch);
                            }
                        }
                    }
                }
            }
        }