Exemple #1
0
 void OnDisable()
 {
     if (!freeItem)
     {
         DragDropHelper.TryRemoveItem(this, attachedTarget);
     }
 }
        public void OnBeginDrag(PointerEventData eventData)
        {
            if (waitingForDragDropStart)
            {
                if (scrollRect)
                {
                    DragDropHelper.TransferEventToScrollRect(eventData, scrollRect);
                }
            }
            else
            {
                if (!delayDetach && scrollRect)
                {
                    bool horizontalDrag = Mathf.Abs(eventData.delta.x) > Mathf.Abs(eventData.delta.y);
                    if (horizontalDrag && !scrollRect.horizontal)
                    {
                        HandleDragDropEvent();
                    }
                    else if (!horizontalDrag && !scrollRect.vertical)
                    {
                        HandleDragDropEvent();
                    }
                    else
                    {
                        DragDropHelper.TransferEventToScrollRect(eventData, scrollRect);
                        return;
                    }
                }

                if (!HandlingDragDropEvent())
                {
                    HandleDragDropEvent();
                }
            }
        }
        void OnDisable()
        {
            if (!freeItem)
            {
                DragDropHelper.TryRemoveItem(this, this.attachedTarget);
            }

            m_parentWhenDragging = null;
            m_waitForSeconds     = null;
            lastTarget           = null;

            DragDropRegistry.Instance.UnRegister(this);
        }
        public void OnInitializePotentialDrag(PointerEventData eventData)
        {
            DragDropEventData.current.Reset();
            scrollRect = DragDropHelper.FindComponentUpward <ScrollRect>(transform);
            DragDropEventData.current.item             = this;
            DragDropEventData.current.eligibleForClick = true;

            lastTarget = attachedTarget;

            waitingForDragDropStart = false;
            if (delayDetach && !freeItem)
            {
                StartCoroutine(DelayHandleDragDropEvent());
            }
        }
Exemple #5
0
        void OnEnable()
        {
            Transform parent = transform.parent;

            if (parent != null)
            {
                DragDropTarget target = parent.gameObject.GetComponent <DragDropTarget>();
                if (target != null)
                {
                    DragDropHelper.TryAddItem(this, target);
                    return;
                }
            }
            Debug.LogError("parent is not a target");
            gameObject.SetActive(false);
        }
Exemple #6
0
        public void OnBeginDrag(PointerEventData eventData)
        {
            if (waitingForDragDropStart)
            {
                if (scrollRect)
                {
                    DragDropHelper.TransferEventToScrollRect(eventData, scrollRect);
                }
            }
            else
            {
                DragDropEventData.current.eligibleForClick = false;
                HandleDragDropEvent();
            }

            if (!HandlingDragDropEvent())
            {
                return;
            }
        }
Exemple #7
0
        public void OnPointerDown(PointerEventData eventData)
        {
            DragDropEventData.current.Reset();
            scrollRect = DragDropHelper.FindComponentUpward <ScrollRect>(transform);
            DragDropEventData.current.item             = this;
            DragDropEventData.current.eligibleForClick = true;

            if (attachedTarget)
            {
                lastTarget = attachedTarget;
            }
            else
            {
                Debug.LogError("will detach from a non-target parent");
            }

            if (delayDetach && !freeItem)
            {
                StartCoroutine(DelayHandleDragDropEvent());
            }
        }
 public DragDropTarget FindDropTarget(PointerEventData pointerEventData, DragDropItem dragDropItem)
 {
     foreach (var ddt in managedTargets)
     {
         if (!ddt.isActiveAndEnabled)
         {
             continue;
         }
         if (!DragDropHelper.IsChannelMatch(ddt, dragDropItem))
         {
             continue;
         }
         bool contain = RectTransformUtility.RectangleContainsScreenPoint(ddt.rectTransform,
                                                                          pointerEventData.position,
                                                                          pointerEventData.pressEventCamera);
         if (contain)
         {
             return(ddt);
         }
     }
     return(null);
 }
Exemple #9
0
        public void OnPointerDown(PointerEventData eventData)
        {
            currentEventData.Reset();
            scrollRect                        = DragDropHelper.FindComponentUpward <ScrollRect>(transform);
            currentEventData.item             = this;
            currentEventData.eligibleForClick = true;

            if (attachedTarget)
            {
                lastTarget = attachedTarget;
                lastParent = attachedTarget.targetParent;
            }
            else
            {
                lastParent = transform.parent;
            }

            if (delayDetach && !freeItem)
            {
                StartCoroutine(DelayHandleDragDropEvent());
            }
        }
Exemple #10
0
        void Start()
        {
            if (!parentWhenDragging)
            {
                parentWhenDragging = DragDropHelper.FindComponentUpward <Canvas>(transform).transform;
            }

            if (!rectTransform)
            {
                rectTransform = GetComponent <RectTransform>();
            }

            if (!freeItem)
            {
                DragDropHelper.InitializePair(this, attachedTarget);
            }

            if (delayDetach)
            {
                waitForSeconds = new WaitForSeconds(longPressDetach);
            }
        }
Exemple #11
0
 private void OnDisable()
 {
     DragDropHelper.RemoveAllItems(this);
     DragDropRegistry.Instance.UnRegister(registerHandle);
     registerHandle = null;
 }