public void OnEndDrag(PointerEventData eventData)
    {
        isDrag = false;

        //float pos = scrollRect.horizontal ? scrollRect.horizontalNormalizedPosition : scrollRect.verticalNormalizedPosition;
        //int index = 0;
        //float offset = Math.Abs(pageArray[index] - pos);
        //for (int i = 1; i < pageArray.Length; i++)
        //{
        //    float _offset = Math.Abs(pageArray[i] - pos);
        //    if (_offset < offset)
        //    {
        //        index = i;
        //        offset = _offset;
        //    }
        //}
        //targetPagePosition = pageArray[index];
        //currentPage = index;
        //OnDragEndEvent?.Invoke(currentPage);

        Vector2 dirV2 = eventData.position - beginPos;
        var     dir   = scrollRect.horizontal ? dirV2.x > 0 : dirV2.y > 0;

        if (Math.Abs(dirV2.x) > scrollDistance)
        {
            if (dir)
            {
                ToPrevious((int page) => { OnDragEndEvent?.Invoke(page); });
            }
            else
            {
                ToNext((int page) => { OnDragEndEvent?.Invoke(page); });
            }
        }
    }
    public void OnDrag(PointerEventData eventData)
    {
        float distance = Vector3.SqrMagnitude(eventData.position - eventData.pressPosition);

        if (distance >= distanceMagnitude && !directionChanged)
        {
            Vector3   dirVector     = (eventData.position - eventData.pressPosition).normalized;
            Direction dragDirection = DirectionHelper.GetDragDirection(dirVector);
            OnDragEndEvent?.Invoke(dragDirection);
            directionChanged = true;
        }
    }
Beispiel #3
0
 public void OnEndDrag(PointerEventData data)
 {
     OnDragEnd.Invoke();
 }