コード例 #1
0
        public void OnDrag(PointerEventData eventData)
        {
            if (eventData.pointerId != draggingPointer)
            {
                eventData.pointerDrag = null;
                return;
            }

            manager.UpdateSelection(initialPosition + manager.GetTouchPosition(eventData.position, eventData.pressEventCamera) - initialTouchPosition);
        }
コード例 #2
0
        public void OnDrag(PointerEventData eventData)
        {
            if (eventData.pointerId != draggingPointer)
            {
                eventData.pointerDrag = null;
                return;
            }

            draggingPointerEventData = eventData;

            Vector2 newPosition       = initialPosition + manager.GetTouchPosition(eventData.position, eventData.pressEventCamera) - initialTouchPosition;
            Vector2 selectionPosition = initialSelectionPosition;
            Vector2 selectionSize     = initialSelectionSize;

            if ((directions & Direction.Left) == Direction.Left)
            {
                if (newPosition.x < manager.SelectionSnapToEdgeThreshold)
                {
                    newPosition.x = 0f;
                }

                selectionSize.x    -= newPosition.x - selectionPosition.x;
                selectionPosition.x = newPosition.x;
            }
            else if ((directions & Direction.Right) == Direction.Right)
            {
                if (newPosition.x > manager.OrientedImageSize.x - manager.SelectionSnapToEdgeThreshold)
                {
                    newPosition.x = manager.OrientedImageSize.x;
                }

                selectionSize.x = newPosition.x - selectionPosition.x;
            }

            if ((directions & Direction.Top) == Direction.Top)
            {
                if (newPosition.y > manager.OrientedImageSize.y - manager.SelectionSnapToEdgeThreshold)
                {
                    newPosition.y = manager.OrientedImageSize.y;
                }

                selectionSize.y = newPosition.y - selectionPosition.y;
            }
            else if ((directions & Direction.Bottom) == Direction.Bottom)
            {
                if (newPosition.y < manager.SelectionSnapToEdgeThreshold)
                {
                    newPosition.y = 0f;
                }

                selectionSize.y    -= newPosition.y - selectionPosition.y;
                selectionPosition.y = newPosition.y;
            }

            bool shouldExpand = false;

            if (secondaryDirection == Direction.None)
            {
                if (direction == Direction.Left || direction == Direction.Right)
                {
                    if (selectionSize.x > initialSelectionSize.x)
                    {
                        shouldExpand = true;
                    }
                }
                else
                {
                    if (selectionSize.y > initialSelectionSize.y)
                    {
                        shouldExpand = true;
                    }
                }
            }

            manager.UpdateSelection(selectionPosition, selectionSize, pivot, !shouldExpand);
        }