Пример #1
0
        /// <summary>
        /// When dragging is occurring this will be called every time the cursor is moved.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public virtual void OnDrag(PointerEventData eventData)
        {
            var movement = 0f;

            var size = (ScrollRect.transform as RectTransform).rect.size;

            var max_x = Mathf.Max(0f, ScrollRect.content.rect.width - size.x);
            var max_y = Mathf.Max(0f, ScrollRect.content.rect.height - size.y);

            if (ScrollRect.content.anchoredPosition.y < 0f)
            {
                movement      = -ScrollRect.content.anchoredPosition.y;
                pullDirection = PullDirection.Up;
            }
            else if (ScrollRect.content.anchoredPosition.y > max_y)
            {
                movement      = ScrollRect.content.anchoredPosition.y - max_y;
                pullDirection = PullDirection.Down;
            }
            else if (ScrollRect.content.anchoredPosition.x < 0f)
            {
                movement      = -ScrollRect.content.anchoredPosition.x;
                pullDirection = PullDirection.Left;
            }
            else if (ScrollRect.content.anchoredPosition.x > max_x)
            {
                movement      = ScrollRect.content.anchoredPosition.x - max_x;
                pullDirection = PullDirection.Right;
            }

            if (movement >= RequiredMovement)
            {
                if (!isPullValid)
                {
                    OnPullAllowed.Invoke(pullDirection);
                    isPullValid = true;
                }
            }
            else
            {
                if (isPullValid)
                {
                    OnPullCancel.Invoke(pullDirection);
                    isPullValid   = false;
                    pullDirection = PullDirection.None;
                }
            }
        }
    private void HandlePullDirection()
    {
        var isVerticalPull   = Mathf.Abs(Input.GetAxis("Mouse Y")) > rotationThreshold;
        var isHorizontalPull = Mathf.Abs(Input.GetAxis("Mouse X")) > rotationThreshold;

        if (isVerticalPull)
        {
            this.pullDirection = PullDirection.Vertical;
        }
        else if (isHorizontalPull)
        {
            this.pullDirection = PullDirection.Horizontal;
        }
        else
        {
            this.pullDirection = PullDirection.None;
        }
    }
Пример #3
0
 /// <summary>
 /// Resets the drag values.
 /// </summary>
 protected virtual void ResetDrag()
 {
     pullDirection = PullDirection.None;
     isPullValid   = false;
 }