63 lines
1.7 KiB
C#
63 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
// InventoryUI.cs
|
|
|
|
public class ToolbarUIController : MonoBehaviour
|
|
{
|
|
public Transform itemParent;
|
|
public ToolbarManager toolbarManager;
|
|
public PrefabManager prefabManager;
|
|
|
|
private readonly Dictionary<int, GameObject> _slots = new();
|
|
|
|
private void Start()
|
|
{
|
|
Debug.Log("ToolbarUI 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 (toolbarManager.Slots.Count == 0)
|
|
toolbarManager.InitializeToolbar();
|
|
|
|
var slotPrefab = prefabManager.GetSlotPrefab();
|
|
// var itemPrefab = prefabManager.GetItemPrefab();
|
|
|
|
|
|
foreach (var toolbarSlot in toolbarManager.Slots)
|
|
{
|
|
// Draw slots to screen
|
|
var slotDisplay = Instantiate(slotPrefab, itemParent);
|
|
|
|
slotDisplay.transform.localScale = new Vector3(1, 1, 1);
|
|
|
|
var i = toolbarSlot.Key;
|
|
|
|
var slotComponent = slotDisplay.GetComponent<SlotComponent>();
|
|
|
|
// Add prefab to slot
|
|
slotComponent.SetSlotDetails(toolbarSlot.Value);
|
|
|
|
_slots.Add(i, slotDisplay);
|
|
}
|
|
|
|
Debug.Log("Finished adding items to toolbar 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.
|
|
}
|
|
} |