add basic inventory, fading walls
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ItemSlotUI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
// Kind of confusing here... ItemSlot refers to the class that is the DATA for a
|
||||
// "slot". It is used for serialization and keeping track of the inventory in data.
|
||||
// ItemSlot simply has an item ID and a quantity. ItemSlotUI is the visual represenation of this.
|
||||
private ItemSlot slotData;
|
||||
private int quantity;
|
||||
private Image image;
|
||||
|
||||
private Item itemObj;
|
||||
|
||||
// (I hate this approach) passed in from InventorySlotUI
|
||||
private ItemNameUI itemNameUI;
|
||||
private ItemDescriptionUI itemDescriptionUI;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
image = GetComponentsInChildren<Image>()[1]; //ignore parent
|
||||
}
|
||||
|
||||
public void LoadImage(ItemNameUI itemNameUI, ItemDescriptionUI itemDescriptionUI)
|
||||
{
|
||||
if (this.itemNameUI == null) this.itemNameUI = itemNameUI;
|
||||
if (this.itemDescriptionUI == null) this.itemDescriptionUI = itemDescriptionUI;
|
||||
|
||||
itemObj = new Item(slotData.item);
|
||||
image.sprite = Resources.Load<Sprite>(itemObj.itemImagePath);
|
||||
}
|
||||
|
||||
public void SetItem(ItemSlot itemSlot)
|
||||
{
|
||||
this.slotData = itemSlot;
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData pointerEventData)
|
||||
{
|
||||
if (itemObj != null && itemObj.id != ItemIdEnum.NONE)
|
||||
{
|
||||
itemNameUI.nameText = itemObj.itemName;
|
||||
itemDescriptionUI.descriptionText = itemObj.description;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData pointerEventData)
|
||||
{
|
||||
itemNameUI.nameText = "";
|
||||
itemDescriptionUI.descriptionText = "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user