Example #1
0
        public override void OnDrag(PointerEventData eventData)
        {
            base.OnDrag(eventData);

            if (eventData.pointerId > 0 || swipeEnded)
            {
                return;
            }

            bool swipeDistanceTravelled = false;

            if (collection.points.Count > 0)
            {
                if ((eventData.position - collection.points.Last().position).magnitude >= _pointDelta)
                {
                    collection.Add(eventData.position, Time.time);

                    if (forceSwipeAtLength && SwipePointsCollection.GetPointsLength(collection.points) >= _swipeLength)
                    {
                        swipeDistanceTravelled = true;
                    }
                }

                onNewPointAdded?.Invoke(collection.points.Last(), false);
            }
            else
            {
                collection.Add(eventData.position, Time.time);

                onNewPointAdded?.Invoke(collection.points.Last(), true);
            }

            onPointerDrag?.Invoke(eventData.position);

            if (swipeDistanceTravelled)
            {
                ForceSwipe();
            }
        }
Example #2
0
        public static Swipe Solve(SwipeSolveMethod method, List <SwipePoint> points, int minLength = -1)
        {
            List <SwipePoint> _points = new List <SwipePoint>();

            if (points.Count > 2)
            {
                float angle = 0f;
                int   pointIndex;

                switch (method)
                {
                case SwipeSolveMethod.BY_LAST_ANGLE:
                    pointIndex = points.Count - 1;

                    do
                    {
                        _points.Add(points[pointIndex]);
                        pointIndex--;
                    }while (pointIndex >= 0 && (angle + points[pointIndex].angleDelta) < MAX_ANGLE_DEVIATION);

                    _points.Reverse();

                    break;

                case SwipeSolveMethod.BY_LENGTH:
                    List <SwipePoint> currentGroup;

                    for (pointIndex = 0; pointIndex < points.Count; pointIndex++)
                    {
                        angle        = 0f;
                        currentGroup = new List <SwipePoint>();

                        for (int groupIndex = pointIndex; groupIndex < points.Count; groupIndex++)
                        {
                            if (groupIndex > pointIndex)
                            {
                                angle += points[groupIndex].angleDelta;
                            }

                            currentGroup.Add(points[groupIndex]);

                            if (Mathf.Abs(angle) > MAX_ANGLE_DEVIATION || groupIndex == points.Count - 1)
                            {
                                if (SwipePointsCollection.GetPointsLength(currentGroup) >
                                    SwipePointsCollection.GetPointsLength(_points))
                                {
                                    _points = new List <SwipePoint>(currentGroup);

                                    if (SwipePointsCollection.GetPointsLength(_points)
                                        >= (SwipePointsCollection.GetPointsLength(points) * .5f))
                                    {
                                        return(new Swipe(_points));
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }

                    break;

                case SwipeSolveMethod.BY_LAST_ANGLE_NOT_CUMULATIVE:
                    int _index = points.Count - 1;

                    do
                    {
                        _points.Add(points[_index]);
                        _index--;
                    }while (_index >= 0 && points[_index].angleDelta < MAX_ANGLE_DEVIATION);

                    _points.Reverse();

                    break;
                }
            }
            else
            {
                _points = points;
            }

            return(new Swipe(_points));
        }