public void UnequipTo(EquipSlotNameType equipSlotName, int invSlotIndex, bool addToInventory = true) { int equipSlotIndex = (int)equipSlotName; ExpendableItem oldItem; if ((oldItem = _equippedItems[equipSlotIndex]) != null) { if (addToInventory) { if (invSlotIndex == -1) { invSlotIndex = _inventory.FirstFreeSlot(); } if (!_inventory.AddAt(oldItem, invSlotIndex)) { return; } } _equippedItems[equipSlotIndex] = null; EventManager.Instance.RemoveListener(EventName.WalkDistanceThresholdReached, oldItem.ReduceDurability); Debug.Log($"Unequipped {oldItem.Item.ItemName}."); EventManager.Instance.InvokeEvent(EventName.EquipmentChanged, new EquipmentChangedEventArgs(oldItem.Item, null, equipSlotName)); } }
public void OnPointerDown(PointerEventData e) { if (e.button == PointerEventData.InputButton.Right && inventoryHook.GetCursorSlot().gameObject.activeInHierarchy) { Inventory inv = inventoryHook.GetInventory(); ItemStack stack = inv.GetAt(inventoryHook.GetCursorSlot().slot); ItemStack thisStack = inv.GetAt(slot); inv.AddAt(slot, stack.GetItem(), 1); inv.RemoveAt(inventoryHook.GetCursorSlot().slot, 1); stack = inv.GetAt(inventoryHook.GetCursorSlot().slot); // Update the cursor count to match inventoryHook.GetCursorSlot().countText.text = stack.GetAmount().ToString(); inventoryHook.GetCursorSlot().countObject.SetActive(stack.GetAmount() > 1); // Stop dragging if we no longer have a valid item if (stack.IsValid() == false) { ResetDrag(); } } }