mirror of
https://github.com/DerTyp7/example-top-down-unity.git
synced 2025-10-30 21:07:09 +01:00
i
This commit is contained in:
@@ -24,9 +24,9 @@ public class Inventory : MonoBehaviour
|
||||
|
||||
public Item testItemType;
|
||||
|
||||
public static Action OnInventoryChanged;
|
||||
public static Action OnItemAdded;
|
||||
public static Action OnItemRemoved;
|
||||
public static Action OnPlayerInventoryChanged;
|
||||
public static Action OnPlayerItemAdded;
|
||||
public static Action OnPlayerItemRemoved;
|
||||
|
||||
[Header("Inventory")]
|
||||
[SerializeField]
|
||||
@@ -35,16 +35,22 @@ public class Inventory : MonoBehaviour
|
||||
[SerializeField]
|
||||
int maxSpaceOfSlots = 10;
|
||||
|
||||
[SerializeField]
|
||||
bool isPlayerInventory = true;
|
||||
|
||||
[SerializeField]
|
||||
List<Slot> inventory = new List<Slot>();
|
||||
|
||||
public List<Slot> GetInventory() => inventory;
|
||||
|
||||
public void AddSlots(int _numberOfSlots)
|
||||
{
|
||||
for (int i = 0; i < _numberOfSlots; i++)
|
||||
{
|
||||
inventory.Add(new Slot());
|
||||
}
|
||||
OnInventoryChanged?.Invoke();
|
||||
if(isPlayerInventory)
|
||||
OnPlayerInventoryChanged?.Invoke();
|
||||
}
|
||||
Slot GetEmptySlot()
|
||||
{
|
||||
@@ -143,8 +149,13 @@ public class Inventory : MonoBehaviour
|
||||
rest = count - slot.GetCount();
|
||||
slot.Clear();
|
||||
}
|
||||
OnInventoryChanged?.Invoke();
|
||||
OnItemRemoved?.Invoke();
|
||||
|
||||
if (isPlayerInventory)
|
||||
{
|
||||
OnPlayerInventoryChanged?.Invoke();
|
||||
OnPlayerItemRemoved?.Invoke();
|
||||
}
|
||||
|
||||
return rest;
|
||||
}
|
||||
else
|
||||
@@ -204,8 +215,12 @@ public class Inventory : MonoBehaviour
|
||||
else
|
||||
return -1;
|
||||
|
||||
OnInventoryChanged?.Invoke();
|
||||
OnItemAdded?.Invoke();
|
||||
if (isPlayerInventory)
|
||||
{
|
||||
OnPlayerInventoryChanged?.Invoke();
|
||||
OnPlayerItemAdded?.Invoke();
|
||||
}
|
||||
|
||||
return rest;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user