Some checks failed
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Has been cancelled
Build project / Publish to itch.io (StandaloneLinux64) (push) Has been cancelled
Build project / Publish to itch.io (StandaloneWindows64) (push) Has been cancelled
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Has been cancelled
52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class InventoryUI : MonoBehaviour
|
|
{
|
|
[SerializeField] private Image[] slotImages;
|
|
[SerializeField] private Inventory inventory;
|
|
[SerializeField] private Color normalColor = Color.white;
|
|
[SerializeField] private Color highlightColor = Color.yellow;
|
|
|
|
void Start()
|
|
{
|
|
RefreshUI();
|
|
}
|
|
|
|
public void RefreshUI()
|
|
{
|
|
for (int i = 0; i < slotImages.Length; i++)
|
|
{
|
|
Item itemInSlot = inventory.slots[i];
|
|
if (itemInSlot != null && itemInSlot.itemIcon != null)
|
|
{
|
|
slotImages[i].sprite = itemInSlot.itemIcon;
|
|
slotImages[i].color = normalColor;
|
|
}
|
|
else
|
|
{
|
|
slotImages[i].sprite = null;
|
|
slotImages[i].color = new Color(1, 1, 1, 0);
|
|
}
|
|
}
|
|
|
|
HighlightSlot(inventory.currentSlot);
|
|
}
|
|
|
|
private void HighlightSlot(int slotIndex)
|
|
{
|
|
if (slotIndex < 0 || slotIndex >= slotImages.Length)
|
|
return;
|
|
|
|
for (int i = 0; i < slotImages.Length; i++)
|
|
{
|
|
if (slotImages[i].sprite == null)
|
|
slotImages[i].color = new Color(1, 1, 1, 0);
|
|
else
|
|
slotImages[i].color = normalColor;
|
|
}
|
|
|
|
slotImages[slotIndex].color = highlightColor;
|
|
}
|
|
}
|