added cost amount to items
added Shop UI added Shop.cs * you now can buy items and you lose the cost when bought * shop is scrollable added comments in Inventory.cs, InventorySlot.cs, InventoryUI.cs now showing description when hovering over items in shop or inventory
This commit is contained in:
parent
c9416181fc
commit
ce1f6ed389
30 changed files with 4726 additions and 64 deletions
60
Assets/Scripts/Shop.cs
Normal file
60
Assets/Scripts/Shop.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Shop : MonoBehaviour {
|
||||
#region Singleton
|
||||
|
||||
public static Shop instance;
|
||||
|
||||
private void Awake() {
|
||||
if(instance != null) {
|
||||
Debug.LogWarning("More than one instance of Shop found");
|
||||
}
|
||||
|
||||
instance = this;
|
||||
}
|
||||
|
||||
#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