Scriptum/Assets/Scripts/Inventory/InventorySlot.cs
2022-05-29 12:33:43 +02:00

72 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class InventorySlot : MonoBehaviour
{
[Header("UI Stuff to change")]
[SerializeField] private TextMeshProUGUI slotItemNumberText;
[SerializeField] private Image slotImage;
[Header("Item variable")]
public Item item;
public int countStackableItems = 0;
public ChestPanelController chestPanelController;
public void SetupInventorySlot(Item _item, ChestPanelController _chestPanelController)
{
chestPanelController = _chestPanelController;
if(_item)
{
SetItem(_item);
}
}
public void SetItem(Item _item)
{
item = _item;
ChangeEnableImageView(true);
slotImage.sprite = _item.Image;
countStackableItems +=1;
UpdateItemNumberHolder();
}
private void ChangeEnableImageView(bool _flag)
{
slotImage.enabled = _flag; //!slotImage.enabled;
}
private void ChangeNumberHeldView(bool _flag)
{
slotItemNumberText.enabled = _flag;
}
private void UpdateItemNumberHolder()
{
slotItemNumberText.text = "" + countStackableItems;
}
// Start is called before the first frame update
void Start()
{
if(!item)
{
ChangeEnableImageView(false);
ChangeNumberHeldView(false);
}
}
// Update is called once per frame
void Update()
{
}
}