Files
Sokoban/Assets/Scripts/UI/InitializeLevelUI.cs
2023-06-16 09:26:12 +03:00

94 lines
1.7 KiB
C#

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);
}
}
}