added ItemStorage.cs, ItemStorageSlot.cs, ItemStorageUI.cs

* Inventory, InventorySlot, InventoryUI, Shop, ShopSlot, ShopUI are extending them
This commit is contained in:
dhain 2022-06-02 15:08:21 +02:00
parent d28a1947eb
commit ee6704abc1
13 changed files with 231 additions and 205 deletions

View file

@ -1,72 +1,15 @@
using System;
using System.Collections;
using TMPro;
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
*/
public void UseItem() {
if(_item.GetType() == typeof(UsableItem)) {
((UsableItem) _item).Select();
Debug.Log("using " + _item.displayName);
public override void UseItem() {
if(Item.GetType() == typeof(UsableItem)) {
((UsableItem) Item).Select();
Debug.Log("using " + Item.displayName);
} else {
Debug.Log("Item not usable " + _item.displayName);
Debug.Log("Item not usable " + Item.displayName);
}
}
}