using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace NotificationSamples.Demo
{
///
/// UI list item for purchased inventory items.
///
public class InventoryItem : MonoBehaviour
{
[SerializeField, Tooltip("Label to store the quantity bought.")]
protected TextMeshProUGUI quantityLabel;
[SerializeField]
protected Image icon;
// Quantity of items bought.
private int quantity;
///
/// The item data linked to this UI item.
///
public InventoryItemData ItemData { get; private set; }
///
/// Initialise the item with the specified settings.
///
public void Initialise(InventoryItemData itemData)
{
ItemData = itemData;
icon.sprite = itemData.Icon;
quantity = 1;
UpdateControls();
}
///
/// Called when another item of the same type was received after buying.
///
public void OnReceivedItem()
{
quantity++;
UpdateControls();
}
// Update UI controls.
private void UpdateControls()
{
quantityLabel.text = quantity.ToString();
}
}
}