49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using Fruitomation.Global;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Fruitomation.UI
|
|
{
|
|
public class BuildingMenu : MonoBehaviour
|
|
{
|
|
[System.Serializable] private class BuildingInfo
|
|
{
|
|
public string Name;
|
|
public GameObject Prefab;
|
|
}
|
|
|
|
[Header("References")]
|
|
[SerializeField] private GameCursor Cursor;
|
|
[SerializeField] private GameObject Menu;
|
|
[SerializeField] private GameObject MenuGrid;
|
|
[SerializeField] private GameObject MenuItemPrefab;
|
|
|
|
[Header("Options")]
|
|
[SerializeField] private List<BuildingInfo> BuildingPrefabs;
|
|
|
|
private void Update()
|
|
{
|
|
Menu.SetActive(GameStateController.Is(GameState.BuildingMenu));
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
foreach (BuildingInfo info in BuildingPrefabs)
|
|
{
|
|
GameObject go = Instantiate(MenuItemPrefab, MenuGrid.transform);
|
|
Text text = go.GetComponentInChildren<Text>();
|
|
|
|
text.text = info.Name;
|
|
|
|
Button butt = go.GetComponent<Button>();
|
|
butt.onClick.AddListener(() =>
|
|
{
|
|
GameStateController.State = GameState.Building;
|
|
Cursor.SetSelectedBuildingToBuild(info.Prefab);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|