using System.Collections.Generic; using Managers; using UnityEngine; // InventoryUI.cs public class InventoryUIController : MonoBehaviour { public Transform itemParent; public InventoryManager inventoryManager; public PrefabManager prefabManager; private readonly Dictionary _slots = new(); private void Start() { Debug.Log("InventoryUI Start"); if (itemParent == null) { Debug.LogWarning("ItemParent is null! Can not attach"); return; } // Delete existing children if any. foreach (Transform child in itemParent) Destroy(child.gameObject); if (inventoryManager.Slots.Count == 0) inventoryManager.InitializeInventory(PlayerManager.Instance.playerData); var slotPrefab = prefabManager.GetSlotPrefab(); var itemPrefab = prefabManager.GetItemPrefab(); foreach (var inventorySlot in inventoryManager.Slots) { // Draw slots to screen var slotDisplay = Instantiate(slotPrefab, itemParent); var i = inventorySlot.Key; var inventorySlotComponent = slotDisplay.GetComponent(); // Add prefab to slot inventorySlotComponent.SetSlotDetails(inventorySlot.Value); _slots.Add(i, slotDisplay); } Debug.Log("Finished adding items to slots"); } public void ListChildren(GameObject parent) { foreach (Transform child in parent.transform) Debug.Log("Child: " + child.name); } public void UpdateUI() { // Get values from inventory and redraw the inventory slots based on that. } }