Esempio n. 1
0
        private void OnDrop(PointerEventData eventData)
        {
            if (m_selectedItem == null || m_selectedSlot == null)
            {
                return;
            }

            DropItem?.Invoke();

            if (ItemUtilities.TryGetSlot(eventData.pointerEnter, out var targetSlot))
            {
                if (targetSlot.IsEmpty && targetSlot.CanDropItem(m_selectedItem))
                {
                    //just add item to an empty slot
                    targetSlot.Add(m_selectedItem);
                }
                else if (targetSlot.IsStackableWith(m_selectedItem))
                {
                    if (targetSlot.TryStackItem(m_selectedItem))
                    {
                        //if stacking where successful, reset and stop here
                        ResetSelection();
                        return;
                    }

                    //targetSlot / item has already maximum stacks
                    //add selected item back to selected slot
                    m_selectedSlot.Add(m_selectedItem);
                }
                else
                {
                    if (targetSlot.CanDropItem(m_selectedItem))
                    {
                        //switch items
                        var otherItem = targetSlot.Content;
                        targetSlot.Remove();
                        m_selectedSlot.Add(otherItem);
                        targetSlot.Add(m_selectedItem);
                    }
                    else
                    {
                        m_selectedSlot.Add(m_selectedItem);
                    }
                }
            }
            else
            {
                //reset to origin, no slot available
                m_selectedSlot.Add(m_selectedItem);
            }

            //in any case reset selected slot, selected item and disable icon
            ResetSelection();
        }
Esempio n. 2
0
 private void CheckDragableItem(PointerEventData eventData)
 {
     if (ItemUtilities.TryGetSlot(eventData.pointerEnter, out var targetSlot))
     {
         if (!targetSlot.IsEmpty)
         {
             DragItem?.Invoke();
             m_selectedSlot = targetSlot;
             m_selectedItem = targetSlot.Content;
             m_selectedSlot.Remove();
             EnableDragableIcon(eventData);
         }
     }
 }
Esempio n. 3
0
        public void OnPointerEnter(GameObject gbj)
        {
            if (!m_enablePreview)
            {
                return;
            }

            if (ItemUtilities.TryGetSlot(gbj, out m_currentTarget))
            {
                if (!m_currentTarget.IsEmpty)
                {
                    var popUpPosition =
                        UiUtilities.AnchoredPosition((RectTransform)m_currentTarget.transform,
                                                     m_previewPopup.RectTransform,
                                                     m_rectAnchor, m_offset);

                    m_previewPopup.transform.SetAsLastSibling();
                    m_previewPopup.Show(m_currentTarget, popUpPosition);
                }
            }
        }