Exemple #1
0
 public void Add(HotbarItem itemToAdd)
 {
     //Loop through each hotbar slot.
     foreach (HotbarSlot hotbarSlot in hotbarSlots)
     {
         //If the item is successfully added to the slot then return.
         if (hotbarSlot.AddItem(itemToAdd))
         {
             return;
         }
     }
 }
Exemple #2
0
        public bool AddItem(HotbarItem itemToAdd)
        {
            //Make sure the slot is empty.
            if (SlotItem != null)
            {
                return(false);
            }

            //Set the slot's item to the item being added.
            SlotItem = itemToAdd;

            return(true);
        }
Exemple #3
0
        public override void OnDrop(PointerEventData eventData)
        {
            //Make sure the dropper has the "ItemDragHandler" component.
            ItemDragHandler itemDragHandler = eventData.pointerDrag.GetComponent <ItemDragHandler>();

            if (itemDragHandler == null)
            {
                return;
            }

            //Make sure the dropped item is from the inventory.
            InventorySlot inventorySlot = itemDragHandler.ItemSlotUI as InventorySlot;

            if (inventorySlot != null)
            {
                //Set our item to the dropped item.
                SlotItem = inventorySlot.ItemSlot.item;
                return;
            }

            //Make sure the dropped item is from the spellbook.
            SpellSlot spellSlot = itemDragHandler.ItemSlotUI as SpellSlot;

            if (spellSlot != null)
            {
                //Set our item to the dropped item(spell).
                SlotItem = spellSlot.SlotItem;
                return;
            }

            //Make sure the dropped item is from the hotbar.
            HotbarSlot hotbarSlot = itemDragHandler.ItemSlotUI as HotbarSlot;

            if (hotbarSlot != null)
            {
                //Swap the dropped item with our item.
                HotbarItem oldItem = SlotItem;
                SlotItem            = hotbarSlot.SlotItem;
                hotbarSlot.SlotItem = oldItem;
                return;
            }
        }
Exemple #4
0
 private void SetItemQuantityUI()
 {
     //Make sure our item is from the inventory.
     if (SlotItem is InventoryItem inventoryItem)
     {
         //Make sure the item is in the inventory.
         if (playerInventory.ItemHolder.HasItem(inventoryItem))
         {
             //Get the quantity of the item and set the quantity text accordingly.
             int quantityCount = playerInventory.ItemHolder.GetTotalQuantity(inventoryItem);
             itemQuantityText.text = quantityCount > 1 ? quantityCount.ToString() : "";
         }
         else
         {
             //Clear the slot
             SlotItem = null;
         }
     }
     else
     {
         //Disable the quantity text.
         itemQuantityText.enabled = false;
     }
 }
Exemple #5
0
 public HotbarSlotData(HotbarItem hotbarItem, int slotIndex)
 {
     this.hotbarItem = hotbarItem;
     this.slotIndex  = slotIndex;
 }
Exemple #6
0
 public void AddSlotData(HotbarItem hotbarItem, int slotIndex) => hotbarSlotData.Add(new HotbarSlotData(hotbarItem, slotIndex));