added ItemStorage.cs, ItemStorageSlot.cs, ItemStorageUI.cs
* Inventory, InventorySlot, InventoryUI, Shop, ShopSlot, ShopUI are extending them
This commit is contained in:
parent
d28a1947eb
commit
ee6704abc1
13 changed files with 231 additions and 205 deletions
|
|
@ -1,7 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Shop : MonoBehaviour {
|
||||
public class Shop : ItemStorage {
|
||||
#region Singleton
|
||||
|
||||
public static Shop instance;
|
||||
|
|
@ -15,46 +15,4 @@ public class Shop : MonoBehaviour {
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public Dictionary<Item, int> items;
|
||||
public Item[] tempItems;
|
||||
|
||||
/**
|
||||
* Methods can be added to this and they will get called every time onItemChangedCallback gets Invoked
|
||||
*/
|
||||
public delegate void OnItemChanged();
|
||||
public OnItemChanged onItemChangedCallback;
|
||||
|
||||
private void Start() {
|
||||
items ??= new Dictionary<Item, int>();
|
||||
foreach(Item item in tempItems) {
|
||||
AddItem(item, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified amount of items to the Shop
|
||||
*/
|
||||
public void AddItem(Item item, int amount) {
|
||||
if(!items.ContainsKey(item)) {
|
||||
items.Add(item, amount);
|
||||
} else {
|
||||
items[item] += amount;
|
||||
}
|
||||
|
||||
onItemChangedCallback?.Invoke();
|
||||
}
|
||||
// TODO: add to buy more than one item
|
||||
/**
|
||||
* Removes the specified amount of items in the Shop
|
||||
*/
|
||||
public void RemoveItem(Item item, int amount) {
|
||||
if(items[item] <= 0) {
|
||||
items.Remove(item);
|
||||
} else {
|
||||
items[item] -= amount;
|
||||
}
|
||||
|
||||
onItemChangedCallback?.Invoke();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue