public void AddItem(InventoryItemBase item) { Debug.Log("You are adding a " + item); if (item.ItemType == ItemType.Key) { KeyManager.SetKeyActive(item.Name, true); } if (item.ItemType == ItemType.LegendSwordPiece) { LegendSwordEvents.FireAnEvent_OnLegendarySwordPieceLooted(item.Name); } //make a temporary Stack. FindStackableSlot runs 10 times if your NUMBER OF SLOTS is 10. InventorySlotStack freeSlot = FindStackableSlot(item); if (freeSlot == null) { Debug.Log("An item you don't currently have has been added to an empty slot "); freeSlot = FindNextEmptySlot(); } if (freeSlot != null) { //Debug.Log("Item added"); freeSlot.AddItem(item); Debug.Log("You have " + freeSlot.Count + " " + item + "'s"); if (OnItemAdded != null) { Debug.Log("I raised an OnItemAdded event to let your HUD know you added an item so it can update your UI."); OnItemAdded(this, new InventoryEventArgs(item, false)); } } }
public void RemoveItem(InventoryItemBase item) { if (item.ItemType == ItemType.Key) { KeyManager.SetKeyActive(item.Name, false); } if (item.ItemType == ItemType.LegendSwordPiece) { LegendSwordEvents.FireAnEvent_OnLegendarySwordPieceDropped(item.Name); } foreach (InventorySlotStack slot in m_ListOfSlotStacks) { if (slot.Remove(item)) { if (OnItemRemoved != null) { //update delgates item has been removed OnItemRemoved(this, new InventoryEventArgs(item, false)); } break; } } }