Пример #1
0
        protected virtual void Update()
        {
            // Get fingers
            var fingers = Use.GetFingers();

            if (fingers.Count > 0)
            {
                var screenFrom = LeanGesture.GetStartScreenCenter(fingers);
                var screenTo   = LeanGesture.GetScreenCenter(fingers);
                var finalDelta = screenTo - screenFrom;
                var timeScale  = 1.0f;

                if (ScaleByTime == true)
                {
                    timeScale = Time.deltaTime;
                }

                switch (Coordinate)
                {
                case CoordinateType.ScaledPixels:     finalDelta *= LeanTouch.ScalingFactor; break;

                case CoordinateType.ScreenPercentage: finalDelta *= LeanTouch.ScreenFactor;  break;
                }

                finalDelta *= Multiplier;

                if (onVector != null)
                {
                    onVector.Invoke(finalDelta * timeScale);
                }

                if (onDistance != null)
                {
                    onDistance.Invoke(finalDelta.magnitude * timeScale);
                }

                var worldFrom = ScreenDepth.Convert(screenFrom, gameObject);
                var worldTo   = ScreenDepth.Convert(screenTo, gameObject);

                if (onWorldFrom != null)
                {
                    onWorldFrom.Invoke(worldFrom);
                }

                if (onWorldTo != null)
                {
                    onWorldTo.Invoke(worldTo);
                }

                if (onWorldDelta != null)
                {
                    onWorldDelta.Invoke((worldTo - worldFrom) * timeScale);
                }

                if (onWorldFromTo != null)
                {
                    onWorldFromTo.Invoke(worldFrom, worldTo);
                }
            }
        }
Пример #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);
                            }
                        }
                    }
                }
            }
        }