/// <summary>
        /// Called when we stopp dragging.
        /// </summary>
        /// <param name="eventData"></param>
        public void OnEndDrag(PointerEventData eventData)
        {
            GameObject pointerEnter = eventData.pointerEnter;

            if (pointerEnter != null)
            {
                ISlotDropHandler dropArea = pointerEnter.GetComponent <ISlotDropHandler>();
                if (dropArea != null)
                {
                    dropArea.OnDrop(this);
                    if (m_DragHandler != null)
                    {
                        m_DragHandler.CleanUp();
                        m_DragHandler = null;
                    }
                    return;
                }
            }

            if (m_DragHandler == null)
            {
                return;
            }

            Interface.DragEnded(m_DragHandler);
            m_DragHandler.CleanUp();
            m_DragHandler = null;
        }
        /// <summary>
        /// Called when the item is being dragged.
        /// </summary>
        /// <param name="eventData"></param>
        public void OnDrag(PointerEventData eventData)
        {
            if (Item == null)
            {
                return;
            }

            if (m_DragHandler == null)
            {
                m_DragHandler = new SlotDragHandlerData(this);
            }

            m_DragHandler.Draw(m_ItemIconImage.rectTransform.rect.size, eventData);
        }
예제 #3
0
        /// <summary>
        /// Executed when an item slot drag has been ended.
        /// </summary>
        /// <param name="dragHandler">The drag handler.</param>
        public virtual void DragEnded(SlotDragHandlerData dragHandler)
        {
            if (dragHandler == null)
            {
                return;
            }

            if (!dragHandler.IsDirty())
            {
                return;
            }

            //Debug.Log(
            //    string.Format("Dragged from slot {0} in collection {1} to slot {2} in collection {3}.",
            //    dragHandler.Source.Index, dragHandler.Source.Interface.name,
            //    dragHandler.Hovered.Index, dragHandler.Hovered.Interface.name));

            Collection.Inventory.MoveItem(
                dragHandler.Source.Item,
                dragHandler.Source.Index,
                dragHandler.Source.Interface.Collection,
                dragHandler.Hovered.Index,
                dragHandler.Hovered.Interface.Collection);
        }
 private void OnDisable()
 {
     m_IsHovered = false;
     m_DragHandler?.CleanUp();
     m_DragHandler = null;
 }