91 lines
2.4 KiB
C#
91 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Level
|
|
{
|
|
public class LevelBuilderButtons : MonoBehaviour
|
|
{
|
|
public enum PlacementOption
|
|
{
|
|
None,
|
|
Block,
|
|
Ground,
|
|
Crate,
|
|
Player,
|
|
Environment
|
|
}
|
|
|
|
[System.Serializable]
|
|
public struct PlacementOptionButton
|
|
{
|
|
public GameObject gameObject;
|
|
public Image bgImage;
|
|
public Button button;
|
|
public PlacementOption placementOption;
|
|
}
|
|
|
|
// Private
|
|
[SerializeField] private GameObject buttonsContainer;
|
|
[SerializeField] private PlacementOptionButton[] placementOptionButtons;
|
|
[SerializeField] private Color defaultColor;
|
|
[SerializeField] private Color selectedColor;
|
|
|
|
private PlacementOption currentOption;
|
|
|
|
// Properties
|
|
public PlacementOption CurrentOption => currentOption;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
foreach (PlacementOptionButton placementOptionButton in placementOptionButtons)
|
|
{
|
|
placementOptionButton.button.onClick.AddListener(() => ChangeActiveOption(placementOptionButton.placementOption));
|
|
placementOptionButton.bgImage.color = defaultColor;
|
|
}
|
|
|
|
buttonsContainer.SetActive(false);
|
|
}
|
|
|
|
|
|
private void Start()
|
|
{
|
|
GameManager.Instance.GameStateChanged += OnGameStateChanged;
|
|
}
|
|
|
|
|
|
public void ToggleUI()
|
|
{
|
|
buttonsContainer.SetActive(!buttonsContainer.activeSelf);
|
|
}
|
|
|
|
|
|
private void ChangeActiveOption(PlacementOption placementOption)
|
|
{
|
|
currentOption = placementOption;
|
|
foreach (PlacementOptionButton placementOptionButton in placementOptionButtons)
|
|
{
|
|
if (placementOptionButton.placementOption == placementOption)
|
|
{
|
|
placementOptionButton.bgImage.color = selectedColor;
|
|
}
|
|
else
|
|
{
|
|
placementOptionButton.bgImage.color = defaultColor;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void OnGameStateChanged(GameState newState)
|
|
{
|
|
if (newState == GameState.Gameplay)
|
|
{
|
|
buttonsContainer.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|