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
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -7,30 +8,44 @@ public class InventoryUI : MonoBehaviour {
|
|||
private Inventory _inventory;
|
||||
private InventorySlot[] _slots;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start() {
|
||||
private void Start() {
|
||||
// Get Inventory instance and add UpdateUI method to OnItemChanged delegate
|
||||
_inventory = Inventory.instance;
|
||||
_inventory.onItemChangedCallback += UpdateUI;
|
||||
|
||||
// Add all InventorySlot GameObjects to _slots and turn off the Inventory UI
|
||||
_slots = itemsParent.GetComponentsInChildren<InventorySlot>();
|
||||
ToggleInventory();
|
||||
|
||||
// Set the icon to not be a raycast target for the Description Hovering to work
|
||||
foreach(InventorySlot slot in _slots) {
|
||||
slot.icon.raycastTarget = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
private void Update() {
|
||||
// When "Inventory" button is pressed turn on/off Inventory UI
|
||||
if(Input.GetButtonDown("Inventory")) {
|
||||
ToggleInventory();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn on/off the Inventory UI
|
||||
*/
|
||||
private void ToggleInventory() {
|
||||
inventoryUI.SetActive(!inventoryUI.activeSelf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is called when something in the Inventory 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 < _inventory.items.Count) {
|
||||
_slots[i].AddItem(_inventory.items.ElementAt(i).Key);
|
||||
_slots[i].amountText.text = "" + _inventory.items[_inventory.items.ElementAt(i).Key];
|
||||
} else {
|
||||
_slots[i].ClearSlot();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue