first commit

This commit is contained in:
2026-06-04 18:31:31 +03:00
commit deb988bddf
143 changed files with 13144 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
using UnityEngine;
using UnityEngine.UI;
public class InventoryUI : MonoBehaviour
{
public Inventory inventory;
public Transform slotContainer;
public GameObject slotPrefab;
private void OnEnable()
{
if (inventory != null)
{
inventory.OnInventoryChanged += RefreshUI;
}
RefreshUI();
}
private void OnDisable()
{
if (inventory != null)
{
inventory.OnInventoryChanged -= RefreshUI;
}
}
public void RefreshUI()
{
if (slotContainer == null || slotPrefab == null)
{
return;
}
ClearSlots();
if (inventory == null)
{
return;
}
for (int i = 0; i < inventory.slots.Count; i++)
{
InventorySlot slot = inventory.slots[i];
if (slot == null || slot.IsEmpty())
{
continue;
}
GameObject view = Instantiate(slotPrefab, slotContainer);
view.SetActive(true);
Text label = view.GetComponentInChildren<Text>(true);
if (label != null)
{
label.text = slot.GetDisplayText();
}
Image colorMarker = view.transform.Find("ColorMarker")?.GetComponent<Image>();
if (colorMarker != null && slot.item != null)
{
colorMarker.color = slot.item.itemColor;
}
}
}
public void ClearSlots()
{
if (slotContainer == null)
{
return;
}
for (int i = slotContainer.childCount - 1; i >= 0; i--)
{
Destroy(slotContainer.GetChild(i).gameObject);
}
}
}