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
|
|
@ -4545,7 +4545,7 @@ GameObject:
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
m_StaticEditorFlags: 0
|
m_StaticEditorFlags: 0
|
||||||
m_IsActive: 0
|
m_IsActive: 1
|
||||||
--- !u!114 &1291863650
|
--- !u!114 &1291863650
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
@ -5946,7 +5946,7 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: bc5eb8967b8912c42b93a2086383ddd9, type: 3}
|
m_Script: {fileID: 11500000, guid: bc5eb8967b8912c42b93a2086383ddd9, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
tempItems:
|
startItems:
|
||||||
- {fileID: 11400000, guid: 008a8fdd2c3a95745acafee4087a855d, type: 2}
|
- {fileID: 11400000, guid: 008a8fdd2c3a95745acafee4087a855d, type: 2}
|
||||||
- {fileID: 11400000, guid: 430db451ae959f34b8fba8d8b17276fd, type: 2}
|
- {fileID: 11400000, guid: 430db451ae959f34b8fba8d8b17276fd, type: 2}
|
||||||
- {fileID: 11400000, guid: d651d57ba97a4246a0094409e29fe56a, type: 2}
|
- {fileID: 11400000, guid: d651d57ba97a4246a0094409e29fe56a, type: 2}
|
||||||
|
|
@ -7738,6 +7738,10 @@ PrefabInstance:
|
||||||
m_Modification:
|
m_Modification:
|
||||||
m_TransformParent: {fileID: 1985691912}
|
m_TransformParent: {fileID: 1985691912}
|
||||||
m_Modifications:
|
m_Modifications:
|
||||||
|
- target: {fileID: 5121261193055935939, guid: 2279fa2b47ef2ce40af9052d3a3f438b, type: 3}
|
||||||
|
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
|
||||||
|
value: UseItem
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 5121261193055935940, guid: 2279fa2b47ef2ce40af9052d3a3f438b, type: 3}
|
- target: {fileID: 5121261193055935940, guid: 2279fa2b47ef2ce40af9052d3a3f438b, type: 3}
|
||||||
propertyPath: m_Pivot.x
|
propertyPath: m_Pivot.x
|
||||||
value: 0.5
|
value: 0.5
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class Inventory : MonoBehaviour {
|
public class Inventory : ItemStorage {
|
||||||
#region Singleton
|
#region Singleton
|
||||||
|
|
||||||
public static Inventory instance;
|
public static Inventory instance;
|
||||||
|
|
@ -16,51 +15,17 @@ public class Inventory : MonoBehaviour {
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public Dictionary<Item, int> items;
|
|
||||||
public Item[] startItems;
|
|
||||||
public const int InventorySpace = 28;
|
public const int InventorySpace = 28;
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 startItems) {
|
|
||||||
AddItem(item, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the specified amount of items to the Inventory
|
* Adds the specified amount of items to the Inventory
|
||||||
*/
|
*/
|
||||||
public void AddItem(Item item, int amount) {
|
public override void AddItem(Item item, int amount) {
|
||||||
if(items.Count >= InventorySpace) {
|
if(items.Count >= InventorySpace) {
|
||||||
Debug.Log("Not enough inventory space!");
|
Debug.Log("Not enough inventory space!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!items.ContainsKey(item)) {
|
base.AddItem(item, amount);
|
||||||
items.Add(item, amount);
|
|
||||||
} else {
|
|
||||||
items[item] += amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
onItemChangedCallback?.Invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the specified amount of items in the Inventory
|
|
||||||
*/
|
|
||||||
public void RemoveItem(Item item, int amount) {
|
|
||||||
if(items[item] <= 0) {
|
|
||||||
items.Remove(item);
|
|
||||||
} else {
|
|
||||||
items[item] -= amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
onItemChangedCallback?.Invoke();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,72 +1,15 @@
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using TMPro;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
public class InventorySlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
|
|
||||||
public Image icon;
|
|
||||||
public TextMeshProUGUI amountText;
|
|
||||||
|
|
||||||
public Item _item;
|
|
||||||
|
|
||||||
#region DescriptionHover
|
|
||||||
|
|
||||||
public float timeToWait;
|
|
||||||
|
|
||||||
public void OnPointerEnter(PointerEventData eventData) {
|
|
||||||
StopAllCoroutines();
|
|
||||||
StartCoroutine(StartTimer());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnPointerExit(PointerEventData eventData) {
|
|
||||||
StopAllCoroutines();
|
|
||||||
HoverManager.onMouseExit();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ShowMessage() {
|
|
||||||
if(_item){
|
|
||||||
HoverManager.onMouseHover(_item.description, Input.mousePosition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerator StartTimer() {
|
|
||||||
yield return new WaitForSeconds(timeToWait);
|
|
||||||
|
|
||||||
ShowMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the Item of the Inventory Slot
|
|
||||||
*/
|
|
||||||
public void AddItem(Item newItem) {
|
|
||||||
_item = newItem;
|
|
||||||
|
|
||||||
icon.sprite = _item.defaultSprite;
|
|
||||||
icon.enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears the Inventory Slot
|
|
||||||
*/
|
|
||||||
public void ClearSlot() {
|
|
||||||
_item = null;
|
|
||||||
icon.sprite = null;
|
|
||||||
icon.enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public class InventorySlot : ItemStorageSlot {
|
||||||
/**
|
/**
|
||||||
* Gets called when the Inventory Slot is clicked
|
* Gets called when the Inventory Slot is clicked
|
||||||
*/
|
*/
|
||||||
public void UseItem() {
|
public override void UseItem() {
|
||||||
if(_item.GetType() == typeof(UsableItem)) {
|
if(Item.GetType() == typeof(UsableItem)) {
|
||||||
((UsableItem) _item).Select();
|
((UsableItem) Item).Select();
|
||||||
Debug.Log("using " + _item.displayName);
|
Debug.Log("using " + Item.displayName);
|
||||||
} else {
|
} else {
|
||||||
Debug.Log("Item not usable " + _item.displayName);
|
Debug.Log("Item not usable " + Item.displayName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
|
||||||
46
Assets/Scripts/ItemStorage.cs
Normal file
46
Assets/Scripts/ItemStorage.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class ItemStorage : MonoBehaviour {
|
||||||
|
public Dictionary<Item, int> items;
|
||||||
|
public Item[] startItems;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 startItems) {
|
||||||
|
AddItem(item, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the specified amount of items to the Item Storage
|
||||||
|
*/
|
||||||
|
public virtual void AddItem(Item item, int amount) {
|
||||||
|
if(!items.ContainsKey(item)) {
|
||||||
|
items.Add(item, amount);
|
||||||
|
} else {
|
||||||
|
items[item] += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
onItemChangedCallback?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the specified amount of items in the Item Storage
|
||||||
|
*/
|
||||||
|
public void RemoveItem(Item item, int amount) {
|
||||||
|
if(items[item] <= 0) {
|
||||||
|
items.Remove(item);
|
||||||
|
} else {
|
||||||
|
items[item] -= amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
onItemChangedCallback?.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/ItemStorage.cs.meta
Normal file
11
Assets/Scripts/ItemStorage.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 21c02dc661faff342aca965c68c2c13a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
68
Assets/Scripts/ItemStorageSlot.cs
Normal file
68
Assets/Scripts/ItemStorageSlot.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class ItemStorageSlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
|
||||||
|
public Image icon;
|
||||||
|
public TextMeshProUGUI amountText;
|
||||||
|
|
||||||
|
public Item Item => _item;
|
||||||
|
|
||||||
|
private Item _item;
|
||||||
|
|
||||||
|
#region DescriptionHover
|
||||||
|
|
||||||
|
public float timeToWait;
|
||||||
|
|
||||||
|
public void OnPointerEnter(PointerEventData eventData) {
|
||||||
|
StopAllCoroutines();
|
||||||
|
StartCoroutine(StartTimer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnPointerExit(PointerEventData eventData) {
|
||||||
|
StopAllCoroutines();
|
||||||
|
HoverManager.onMouseExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowMessage() {
|
||||||
|
if(_item){
|
||||||
|
HoverManager.onMouseHover(_item.description, Input.mousePosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator StartTimer() {
|
||||||
|
yield return new WaitForSeconds(timeToWait);
|
||||||
|
|
||||||
|
ShowMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Item of the Item Storage Slot
|
||||||
|
*/
|
||||||
|
public void AddItem(Item newItem) {
|
||||||
|
_item = newItem;
|
||||||
|
|
||||||
|
icon.sprite = _item.defaultSprite;
|
||||||
|
icon.enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the Item Storage Slot
|
||||||
|
*/
|
||||||
|
public virtual void ClearSlot() {
|
||||||
|
_item = null;
|
||||||
|
icon.sprite = null;
|
||||||
|
icon.enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets called when the Item Storage Slot is clicked
|
||||||
|
*/
|
||||||
|
public virtual void UseItem() {
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/ItemStorageSlot.cs.meta
Normal file
11
Assets/Scripts/ItemStorageSlot.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b6f14e8c24660e04e9ceb50a7d8e659d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
55
Assets/Scripts/ItemStorageUI.cs
Normal file
55
Assets/Scripts/ItemStorageUI.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class ItemStorageUI : MonoBehaviour {
|
||||||
|
public Transform itemsParent;
|
||||||
|
public GameObject inventoryUI;
|
||||||
|
private Inventory _inventory;
|
||||||
|
private InventorySlot[] _slots;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
if(_inventory.items[_inventory.items.ElementAt(i).Key] > 1) {
|
||||||
|
_slots[i].amountText.text = "" + _inventory.items[_inventory.items.ElementAt(i).Key];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_slots[i].ClearSlot();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/ItemStorageUI.cs.meta
Normal file
11
Assets/Scripts/ItemStorageUI.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 21b91c5ff9ffa4d45a5e71b08b141657
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class Shop : MonoBehaviour {
|
public class Shop : ItemStorage {
|
||||||
#region Singleton
|
#region Singleton
|
||||||
|
|
||||||
public static Shop instance;
|
public static Shop instance;
|
||||||
|
|
@ -15,46 +15,4 @@ public class Shop : MonoBehaviour {
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -5,68 +5,25 @@ using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class ShopSlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
|
public class ShopSlot : ItemStorageSlot {
|
||||||
public Image icon;
|
|
||||||
public Item item;
|
|
||||||
public TextMeshProUGUI nameText;
|
public TextMeshProUGUI nameText;
|
||||||
public TextMeshProUGUI costText;
|
public TextMeshProUGUI costText;
|
||||||
public TextMeshProUGUI amountText;
|
|
||||||
|
|
||||||
private Shop _shop;
|
private Shop _shop;
|
||||||
private Inventory _inventory;
|
private Inventory _inventory;
|
||||||
private PlayerController _playerController;
|
private PlayerController _playerController;
|
||||||
|
|
||||||
#region DescriptionHover
|
|
||||||
|
|
||||||
public float timeToWait;
|
|
||||||
|
|
||||||
public void OnPointerEnter(PointerEventData eventData) {
|
|
||||||
StopAllCoroutines();
|
|
||||||
StartCoroutine(StartTimer());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnPointerExit(PointerEventData eventData) {
|
|
||||||
StopAllCoroutines();
|
|
||||||
HoverManager.onMouseExit();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ShowMessage() {
|
|
||||||
if(item) {
|
|
||||||
HoverManager.onMouseHover(item.description, Input.mousePosition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerator StartTimer() {
|
|
||||||
yield return new WaitForSeconds(timeToWait);
|
|
||||||
|
|
||||||
ShowMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
_shop = Shop.instance;
|
_shop = Shop.instance;
|
||||||
_inventory = Inventory.instance;
|
_inventory = Inventory.instance;
|
||||||
_playerController = PlayerController.instance;
|
_playerController = PlayerController.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the Item of the Shop Slot
|
|
||||||
*/
|
|
||||||
public void AddItem(Item newItem) {
|
|
||||||
item = newItem;
|
|
||||||
|
|
||||||
icon.sprite = item.defaultSprite;
|
|
||||||
icon.enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the Shop Slot
|
* Clears the Shop Slot
|
||||||
*/
|
*/
|
||||||
public void ClearSlot() {
|
public override void ClearSlot() {
|
||||||
item = null;
|
base.ClearSlot();
|
||||||
icon.sprite = null;
|
|
||||||
icon.enabled = false;
|
|
||||||
nameText.text = "";
|
nameText.text = "";
|
||||||
costText.text = "";
|
costText.text = "";
|
||||||
amountText.text = "";
|
amountText.text = "";
|
||||||
|
|
@ -75,13 +32,13 @@ public class ShopSlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||||
/**
|
/**
|
||||||
* Gets called when the Shop Slot is clicked
|
* Gets called when the Shop Slot is clicked
|
||||||
*/
|
*/
|
||||||
public void UseItem() {
|
public override void UseItem() {
|
||||||
if(_playerController.money >= item.cost) {
|
if(_playerController.money >= Item.cost) {
|
||||||
_inventory.AddItem(item, 1);
|
_inventory.AddItem(Item, 1);
|
||||||
_shop.RemoveItem(item, 1);
|
_shop.RemoveItem(Item, 1);
|
||||||
_playerController.money -= item.cost;
|
_playerController.money -= Item.cost;
|
||||||
|
|
||||||
Debug.Log("Buying Item: " + item.displayName);
|
Debug.Log("Buying Item: " + Item.displayName);
|
||||||
Debug.Log("money left: " + _playerController.money);
|
Debug.Log("money left: " + _playerController.money);
|
||||||
} else {
|
} else {
|
||||||
Debug.Log("Not enough money to buy item.");
|
Debug.Log("Not enough money to buy item.");
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@ public class ShopUI : MonoBehaviour {
|
||||||
foreach(ShopSlot slot in _slots) {
|
foreach(ShopSlot slot in _slots) {
|
||||||
slot.icon.raycastTarget = false;
|
slot.icon.raycastTarget = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateUI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update() {
|
private void Update() {
|
||||||
|
|
@ -46,8 +44,8 @@ public class ShopUI : MonoBehaviour {
|
||||||
for(int i = 0; i < _slots.Length; i++) {
|
for(int i = 0; i < _slots.Length; i++) {
|
||||||
if(i < _shop.items.Count) {
|
if(i < _shop.items.Count) {
|
||||||
_slots[i].AddItem(_shop.items.ElementAt(i).Key);
|
_slots[i].AddItem(_shop.items.ElementAt(i).Key);
|
||||||
_slots[i].nameText.text = _slots[i].item.displayName;
|
_slots[i].nameText.text = _slots[i].Item.displayName;
|
||||||
_slots[i].costText.text = _slots[i].item.cost + " €";
|
_slots[i].costText.text = _slots[i].Item.cost + " €";
|
||||||
_slots[i].amountText.text = _shop.items[_shop.items.ElementAt(i).Key] + " #";
|
_slots[i].amountText.text = _shop.items[_shop.items.ElementAt(i).Key] + " #";
|
||||||
} else {
|
} else {
|
||||||
_slots[i].ClearSlot();
|
_slots[i].ClearSlot();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue