diesmal wirklich
This commit is contained in:
parent
25f51c2622
commit
2ff7fc2c12
20 changed files with 247 additions and 194 deletions
56
Assets/Scripts/Inventory.cs
Normal file
56
Assets/Scripts/Inventory.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Inventory : MonoBehaviour {
|
||||
#region Singleton
|
||||
|
||||
public static Inventory instance;
|
||||
|
||||
private void Awake() {
|
||||
if(instance != null) {
|
||||
Debug.LogWarning("More than one instance of Inventory found");
|
||||
}
|
||||
|
||||
instance = this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public Dictionary<Item, int> items;
|
||||
public const int inventorySpace = 28;
|
||||
|
||||
public delegate void onItemChanged();
|
||||
public onItemChanged onItemChangedCallback;
|
||||
|
||||
private void Start() {
|
||||
items ??= new Dictionary<Item, int>();
|
||||
}
|
||||
|
||||
public void tempAddItem(Item item) {
|
||||
AddItem(item, 1);
|
||||
}
|
||||
|
||||
public void AddItem(Item item, int amount) {
|
||||
if(items.Count >= inventorySpace) {
|
||||
Debug.Log("Not enough inventory space!");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!items.ContainsKey(item)) {
|
||||
items.Add(item, amount);
|
||||
} else {
|
||||
items[item] += amount;
|
||||
}
|
||||
|
||||
|
||||
onItemChangedCallback?.Invoke();
|
||||
}
|
||||
|
||||
public void removeItem(Item item, int amount) {
|
||||
items.Add(item, -amount);
|
||||
|
||||
onItemChangedCallback?.Invoke();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue