예제 #1
0
        private void AttachUIItem(UIItem uiItem)
        {
            uiItem.transform.SetParent(TheTransform);

            if (uiItem.Item != null)
            {
                uiItem.Item.Data.SlotId = ID;
                uiItem.Item.NSData.Slot = this;
            }
        }
예제 #2
0
        public void OnBeginDrag(PointerEventData eventData)
        {
            DraggedItem           = this;
            _tmpItemStartPosition = transform.position;

            DraggedItemStartSlot = Slot;

            transform.SetParent(MainCanvas.transform);

            TheCanvasGroup.blocksRaycasts = false;
        }
예제 #3
0
        public void OnEndDrag(PointerEventData eventData)
        {
            if (TheTransform.parent == DraggedItemStartSlot)
            {
                TheTransform.position = _tmpItemStartPosition;
            }

            UISlot tmpSlot = GetSlot(true);

            if (tmpSlot == null)
            {
                TheTransform.SetParent(DraggedItemStartSlot.transform);
                // Remove item from inventory

                if (Item != null)
                {
                    EventSystem.EventMessenger.Instance.Raise(new Events.EventRemoveItemFromInventory(DraggedItemStartSlot.InventoryUUID, DraggedItemStartSlot.ThisUIItem.Item, false));
                }

                Item = null;
                UpdateUI();

                // check quantity ??

                // Event item was removed...
            }
            else
            {
                if (tmpSlot.InventoryUUID != DraggedItemStartSlot.InventoryUUID)
                {
                    EventSystem.EventMessenger.Instance.Raise(new Events.EventAddItemToInventory(tmpSlot.InventoryUUID, tmpSlot.ThisUIItem.Item, false));
                }
            }



            // Set Variables back to a safe value
            DraggedItem                   = null;
            DraggedItemStartSlot          = null;
            _tmpItemStartPosition         = TheTransform.position;
            TheCanvasGroup.blocksRaycasts = true;
        }
예제 #4
0
 private void AddUIItem(UIItem uiItem)
 {
     uiItem.transform.SetParent(transform);
     uiItem.Item.BaseData.SlotID = ID;
     uiItem.Item.BaseNSData.Slot = this;
 }
예제 #5
0
        public void OnEndDrag(PointerEventData eventData)
        {
            if (Item == null)
            {
                return;
            }

            // If the parent slot is the same move the item back to its
            // start position
            if (transform.parent == DraggedItemStartSlot)
            {
                transform.position = _tmpItemStartPosition;
            }

            TheCanvasGroup.blocksRaycasts = true;

            // If The item is dragged outside a valid slot remove it
            if (Slot == null)
            {
                //Debug.Log("DRAGGED OUTSIDE INVENTORY");

                // Put the item back to its place
                transform.SetParent(DraggedItemStartSlot.transform);

                EventMessenger.Instance.Raise(new EventRemoveItemFromInventory(Item.BaseData.InventoryUUID, Item, false));

                // If the item was stacked the slot will be null as well
                // so we check if the quantity is greater then 0 to generate drop
                // Trigger event to generate inventory drop
                if ((Item.BaseData as IStackableData).Quantity > 0)
                {
                    Debug.LogWarning("Should send event to generate a drop");
                    // --> EventMessenger.Instance.Raise(new EventInventoryGenerateDrop(DraggedItemStartSlot.InventoryPanel.Inventory, Item));
                }

                DestroyItem();

                return;
            }

            if ((Item.BaseData as IStackableData).Quantity <= 0)
            {
                //Debug.Log("ITEM HAVE NO QUANTITY REMOVING");

                EventMessenger.Instance.Raise(new EventRemoveItemFromInventory(DraggedItemStartSlot.InventoryUUID, Item, false));

                DestroyItem();
                return;
            }

            UpdateSlotInfo();

            // We no longer need this references
            // Set back to a safe value
            DraggedItem           = null;
            DraggedItemStartSlot  = null;
            _tmpItemStartPosition = transform.position;

            ToggleQuantity(true);
            ToggleDamageBar(true);
            UpdateQuantity();
            UpdateDamageBar();
        }