57 lines
1.3 KiB
C#
57 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
//using static Inventory;
|
|
|
|
public class ItemSlotUI : MonoBehaviour
|
|
{
|
|
public Button button;
|
|
public Image icon;
|
|
public TextMeshProUGUI quantityText;
|
|
public Inventory.ItemSlot CurSlot;
|
|
private Outline outline;
|
|
public int index;
|
|
public bool equipped;
|
|
void Awake()
|
|
{
|
|
outline = GetComponent<Outline>();
|
|
}
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
void OnEnable()
|
|
{
|
|
outline.enabled = equipped;
|
|
}
|
|
// sets the item to be displayed in the slot
|
|
public void Set(Inventory.ItemSlot slot)
|
|
{
|
|
CurSlot = slot;
|
|
icon.gameObject.SetActive(true);
|
|
icon.sprite = slot.item.icon;
|
|
quantityText.text = slot.quantity > 1 ? slot.quantity.ToString() : string.Empty;
|
|
if (outline != null)
|
|
outline.enabled = equipped;
|
|
}
|
|
// clears the item slot
|
|
public void Clear()
|
|
{
|
|
CurSlot = null;
|
|
icon.gameObject.SetActive(false);
|
|
quantityText.text = string.Empty;
|
|
}
|
|
// called when we click on the slot
|
|
public void OnButtonClick()
|
|
{
|
|
Inventory.instance.SelectItem(index);
|
|
}
|
|
}
|