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
57
Assets/Scripts/ShopUI.cs
Normal file
57
Assets/Scripts/ShopUI.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class ShopUI : MonoBehaviour {
|
||||
public Transform itemsParent;
|
||||
public GameObject shopUI;
|
||||
private Shop _shop;
|
||||
private ShopSlot[] _slots;
|
||||
|
||||
private void Start() {
|
||||
// Get Shop instance and add UpdateUI method to OnItemChanged delegate
|
||||
_shop = Shop.instance;
|
||||
_shop.onItemChangedCallback += UpdateUI;
|
||||
|
||||
// Add all ShopSlot GameObjects to _slots and turn off the Shop UI
|
||||
_slots = itemsParent.GetComponentsInChildren<ShopSlot>();
|
||||
ToggleShop();
|
||||
|
||||
// Set the icon to not be a raycast target for the Description Hovering to work
|
||||
foreach(ShopSlot slot in _slots) {
|
||||
slot.icon.raycastTarget = false;
|
||||
}
|
||||
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
// When "Shop" button is pressed turn on/off Shop UI
|
||||
if(Input.GetButtonDown("Shop")) {
|
||||
ToggleShop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn on/off the Shop UI
|
||||
*/
|
||||
private void ToggleShop() {
|
||||
shopUI.SetActive(!shopUI.activeSelf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is called when something in the Shop UI should update
|
||||
*/
|
||||
private void UpdateUI() {
|
||||
// Add all items to the correct slots and clear the ones where no item should be
|
||||
for(int i = 0; i < _slots.Length; i++) {
|
||||
if(i < _shop.items.Count) {
|
||||
_slots[i].AddItem(_shop.items.ElementAt(i).Key);
|
||||
_slots[i].nameText.text = _slots[i].item.displayName;
|
||||
_slots[i].costText.text = _slots[i].item.cost + " €";
|
||||
_slots[i].amountText.text = _shop.items[_shop.items.ElementAt(i).Key] + " #";
|
||||
} else {
|
||||
_slots[i].ClearSlot();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue