This commit is contained in:
Janis M
2022-02-22 10:46:31 +01:00
parent 5dfbaf3f30
commit 94654c714a
4 changed files with 50 additions and 26 deletions

View File

@@ -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;
}