Gameplay-Edit
This commit is contained in:
90
Assets/Scripts/UI/LevelBuilderButtons.cs
Normal file
90
Assets/Scripts/UI/LevelBuilderButtons.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user