Gameplay-Edit
This commit is contained in:
93
Assets/Scripts/UI/InitializeLevelUI.cs
Normal file
93
Assets/Scripts/UI/InitializeLevelUI.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using Level;
|
||||
|
||||
public class InitializeLevelUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject uiContainer;
|
||||
[SerializeField] private TextMeshProUGUI widthText;
|
||||
[SerializeField] private TextMeshProUGUI heightText;
|
||||
|
||||
private int width = 5;
|
||||
private int height = 5;
|
||||
|
||||
|
||||
// Properties
|
||||
private int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return width;
|
||||
}
|
||||
set
|
||||
{
|
||||
width = value;
|
||||
widthText.text = width.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return height;
|
||||
}
|
||||
set
|
||||
{
|
||||
height = value;
|
||||
heightText.text = height.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
uiContainer.SetActive(false);
|
||||
Width = 5;
|
||||
Height = 5;
|
||||
}
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
GameManager.Instance.GameStateChanged += OnGameStateChanged;
|
||||
}
|
||||
|
||||
|
||||
public void ToggleUI()
|
||||
{
|
||||
uiContainer.SetActive(!uiContainer.activeSelf);
|
||||
}
|
||||
|
||||
|
||||
public void ChangeWidth(int delta)
|
||||
{
|
||||
Width += delta;
|
||||
Width = Mathf.Clamp(Width, 3, 100);
|
||||
}
|
||||
|
||||
|
||||
public void ChangeHeight(int delta)
|
||||
{
|
||||
Height += delta;
|
||||
Height = Mathf.Clamp(Height, 3, 100);
|
||||
}
|
||||
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
LevelBuilder.Instance.CreateLayout(Width, Height);
|
||||
uiContainer.SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
private void OnGameStateChanged(GameState newState)
|
||||
{
|
||||
if (newState == GameState.Gameplay)
|
||||
{
|
||||
uiContainer.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/InitializeLevelUI.cs.meta
Normal file
11
Assets/Scripts/UI/InitializeLevelUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7aa653a1aba48a849a597b58214e4c9b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/LevelBuilderButtons.cs.meta
Normal file
11
Assets/Scripts/UI/LevelBuilderButtons.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa2c862b0463c9f4da607f6306396ef9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
52
Assets/Scripts/UI/Menu.cs
Normal file
52
Assets/Scripts/UI/Menu.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Level;
|
||||
|
||||
public class Menu : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject menuDropdown;
|
||||
[SerializeField] private GameObject[] buttonsToInitialize; // Buttons that rely on initialized level to work
|
||||
[SerializeField] private GameObject editingButtonsContainer;
|
||||
[SerializeField] private GameObject gameplayButtonsContainer;
|
||||
[SerializeField] private GameObject startMenu;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
menuDropdown.SetActive(false);
|
||||
foreach (GameObject button in buttonsToInitialize)
|
||||
{
|
||||
button.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
LevelBuilder.Instance.LevelInitialized += OnLevelInitialized;
|
||||
GameManager.Instance.GameStateChanged += OnGameStateChanged;
|
||||
}
|
||||
|
||||
|
||||
public void ToggleMenu()
|
||||
{
|
||||
menuDropdown.SetActive(!menuDropdown.activeSelf);
|
||||
}
|
||||
|
||||
|
||||
private void OnLevelInitialized()
|
||||
{
|
||||
foreach (GameObject button in buttonsToInitialize)
|
||||
{
|
||||
button.SetActive(true);
|
||||
}
|
||||
startMenu.SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
private void OnGameStateChanged(GameState newState)
|
||||
{
|
||||
editingButtonsContainer.SetActive(newState == GameState.Editing);
|
||||
gameplayButtonsContainer.SetActive(newState == GameState.Gameplay);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Menu.cs.meta
Normal file
11
Assets/Scripts/UI/Menu.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f29c9409f712ca4a98a87976c634e49
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user