45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using AsteroidGame.Entities.Structures.Scripts;
|
|
using AsteroidGame.Handlers;
|
|
using UnityEditor;
|
|
|
|
namespace AsteroidGame
|
|
{
|
|
public class BuildMenuUiController : MonoBehaviour
|
|
{
|
|
|
|
[Header("Structures")]
|
|
[SerializeField] private StructureBaseScriptableObject availableStructuresObject;
|
|
|
|
private VisualElement m_Root;
|
|
private VisualElement m_SlotContainer;
|
|
private List<StructureBase> buildings = new();
|
|
private BuildingHandler buildingHandler;
|
|
void OnEnable()
|
|
{
|
|
buildings = availableStructuresObject.structureList;
|
|
buildingHandler = FindObjectOfType<BuildingHandler>();
|
|
|
|
//Store the root from the UI Document component
|
|
m_Root = GetComponent<UIDocument>().rootVisualElement;
|
|
m_SlotContainer = m_Root.Q<VisualElement>("Menu");
|
|
|
|
for (int i = 0; i < buildings.Count; i++)
|
|
{
|
|
StructureBase building = buildings[i];
|
|
BuildingButton button = new();
|
|
button.name = building.name;
|
|
button.text = building.UiFriendlyName;
|
|
button.RegisterCallback<ClickEvent, int>((evt, index) =>
|
|
{
|
|
buildingHandler.EnterBuildMode(index);
|
|
},i);
|
|
m_SlotContainer.Add(button);
|
|
}
|
|
}
|
|
}
|
|
}
|