public void Add(ItemData item) { //stack on existing slot foreach (InventorySlotData slot in invSlots) { if (!slot.Empty && slot.Item == item) { slot.Add(item); return; } } //add to empty slot foreach (InventorySlotData slot in invSlots) { if (slot.Empty) { slot.Add(item); return; } } //add extra slot if possible if (invSlots.Count < maxSlots) { InventorySlotData slot = new InventorySlotData(); invSlots.Add(slot); slot.Add(item); } Debug.Log("Inventory is full!"); }
protected override void InitilizeItemSlots() { base.InitilizeItemSlots(); var count = 0; foreach (var equipmentSlot in SlotReferences) { var itemslotData = new ItemSlotData { ParentNetId = AttachedNetworkIdentity.netId, SlotIndex = InventorySlotData.Count + count, SlotType = equipmentSlot.Key }; InventorySlotData.Add(count + Capacity, itemslotData); count++; } }