mirror of
https://github.com/DerTyp7/example-top-down-unity.git
synced 2025-10-29 12:32:09 +01:00
rework
This commit is contained in:
@@ -23,31 +23,23 @@ public class Inventory : MonoBehaviour
|
||||
|
||||
|
||||
public delegate void OnItemChanged();
|
||||
public OnItemChanged onItemChangedCallback; //
|
||||
public OnItemChanged onItemChangedCallback;
|
||||
|
||||
[SerializeField]
|
||||
int numberOfSlots = 20;
|
||||
|
||||
[SerializeField]
|
||||
List<Slot> inventory = new List<Slot>();
|
||||
|
||||
public List<Slot> getInventory { get => inventory;}
|
||||
public void createEmptyInventory(int numberOfSlots, int maxSpaceOfSlots = 10)
|
||||
{
|
||||
// Initializes the inventory with a specific number of slots and slotsize.
|
||||
// !!!Has to be called bevore adding any items!!!
|
||||
// Example createEmptyInventory(5, 10) : 5 Slots with space for 10 items each
|
||||
for (int i = 0; i < numberOfSlots; i++)
|
||||
{
|
||||
inventory.Add(new Slot(maxSpaceOfSlots));
|
||||
}
|
||||
if (onItemChangedCallback != null)
|
||||
onItemChangedCallback.Invoke();
|
||||
}
|
||||
|
||||
public void addInventorySlots(int numberOfSlots, int maxSpaceOfSlots = 10)
|
||||
{
|
||||
// Adds a specific number of slots and slotsize to the inventory.
|
||||
// Example addInventorySlots(5, 10) : Adds 5 Slots with space for 10 items each
|
||||
for (int i = 0; i < numberOfSlots; i++)
|
||||
{
|
||||
inventory.Add(new Slot(maxSpaceOfSlots));
|
||||
inventory.Add(new Slot());
|
||||
}
|
||||
if (onItemChangedCallback != null)
|
||||
onItemChangedCallback.Invoke();
|
||||
@@ -142,4 +134,30 @@ public class Inventory : MonoBehaviour
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public int addItem(Item itemType, int count = 1)
|
||||
{
|
||||
foreach (Slot slot in inventory)
|
||||
{
|
||||
if (slot.ItemType.Equals(itemType))
|
||||
{
|
||||
slot.
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Init Inventory
|
||||
for (int i = 0; i < numberOfSlots; i++)
|
||||
{
|
||||
inventory.Add(new Slot());
|
||||
}
|
||||
if (onItemChangedCallback != null)
|
||||
onItemChangedCallback.Invoke();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,15 +18,12 @@ public class Slot
|
||||
/// </summary>
|
||||
|
||||
Item item;
|
||||
int maxItems = 1;
|
||||
int count = 0;
|
||||
public Item ItemType { get => item; set => item = value; }
|
||||
public int Count { get => count; set => count = value; }
|
||||
public int MaxItems { get => maxItems; set => maxItems = value; }
|
||||
public Slot(int maxItems = 1)
|
||||
public Slot()
|
||||
{
|
||||
item = null;
|
||||
this.maxItems = maxItems;
|
||||
}
|
||||
public void addItem(int count = 1)
|
||||
{
|
||||
@@ -45,7 +42,7 @@ public class Slot
|
||||
}
|
||||
public Slot copy()
|
||||
{
|
||||
Slot slot = new Slot(maxItems);
|
||||
Slot slot = new Slot();
|
||||
slot.count = count;
|
||||
slot.ItemType = ItemType;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user