Example #1
0
        public void OnEndDrag(PointerEventData eventData)
        {
            if (IsOnline && !hasAuthority)
            {
                return;
            }

            CurrentPointerEventData = eventData;
            CurrentDragPhase        = DragPhase.End;

            UpdatePosition();
            if (SecondaryDragAction != null && IsProcessingSecondaryDragAction)
            {
                SecondaryDragAction();
            }

            Vector2 removedOffset = Vector2.zero;
            Vector2 pointerDragOffset;

            if (PointerDragOffsets.TryGetValue(eventData.pointerId, out pointerDragOffset))
            {
                removedOffset = (Vector2)transform.position - eventData.position - pointerDragOffset;
            }
            PointerPositions.Remove(eventData.pointerId);
            PointerDragOffsets.Remove(eventData.pointerId);
            Vector2 otherOffset;

            foreach (int offsetKey in PointerDragOffsets.Keys.ToList())
            {
                if (PointerDragOffsets.TryGetValue(offsetKey, out otherOffset))
                {
                    PointerDragOffsets[offsetKey] = otherOffset - removedOffset;
                }
            }

            if (IsProcessingSecondaryDragAction)
            {
                return;
            }

            if (PlaceHolder != null)
            {
                StartCoroutine(MoveToPlaceHolder());
            }
            else if (ParentCardStack == null)
            {
                Discard();
            }
        }
        public void OnPointerUp(PointerEventData eventData)
        {
            if (CurrentPointerEventData != null && CurrentPointerEventData.pointerId == eventData.pointerId && !eventData.dragging &&
                eventData.button != PointerEventData.InputButton.Middle && eventData.button != PointerEventData.InputButton.Right)
            {
                if (!DidSelectOnDown && EventSystem.current.currentSelectedGameObject == gameObject && DoubleClickAction != null)
                {
                    DoubleClickAction(this);
                }
                else if (PlaceHolder == null)
                {
                    EventSystem.current.SetSelectedGameObject(gameObject, eventData);
                }
            }

            CurrentPointerEventData = eventData;
            if (CurrentDragPhase == DragPhase.Drag)
            {
                return;
            }

            PointerPositions.Remove(eventData.pointerId);
            PointerDragOffsets.Remove(eventData.pointerId);
        }