44 lines
1.5 KiB
C#
44 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using AsteroidGame.Entities;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using AsteroidGame.Handlers;
|
|
using UnityEngine.Serialization;
|
|
|
|
namespace AsteroidGame.UI
|
|
{
|
|
public class BuildMenuUiController : MonoBehaviour
|
|
{
|
|
[FormerlySerializedAs("_availableStructuresObject")]
|
|
[Header("Structures")]
|
|
[SerializeField] private SStructureBaseList _availableSStructuresObject;
|
|
|
|
private VisualElement _mRoot;
|
|
private VisualElement _mSlotContainer;
|
|
private List<StructureBase> _buildings = new();
|
|
private BuildingHandler _buildingHandler;
|
|
|
|
private void OnEnable()
|
|
{
|
|
_buildings = _availableSStructuresObject._structureList;
|
|
_buildingHandler = FindObjectOfType<BuildingHandler>();
|
|
|
|
//Store the root from the UI Document component
|
|
_mRoot = GetComponent<UIDocument>().rootVisualElement;
|
|
_mSlotContainer = _mRoot.Q<VisualElement>("Menu");
|
|
|
|
for (int i = 0; i < _buildings.Count; i++)
|
|
{
|
|
StructureBase building = _buildings[i];
|
|
BuildingButton button = new()
|
|
{
|
|
name = building.name,
|
|
text = building.UiFriendlyName
|
|
};
|
|
button.RegisterCallback<ClickEvent, int>((evt, index) => { _buildingHandler.EnterBuildMode(index); },
|
|
i);
|
|
_mSlotContainer.Add(button);
|
|
}
|
|
}
|
|
}
|
|
} |