2026-02-10 08:18:34 +00:00
|
|
|
using UnityEngine;
|
2026-02-10 11:03:29 +00:00
|
|
|
using UnityEngine.EventSystems;
|
2026-02-10 08:18:34 +00:00
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
public class UIManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public static UIManager instance;
|
|
|
|
|
|
|
|
|
|
[SerializeField] private Text livesText;
|
|
|
|
|
[SerializeField] private Text timeText;
|
2026-02-10 11:03:29 +00:00
|
|
|
|
2026-02-10 08:18:34 +00:00
|
|
|
[SerializeField] private GameObject pausePanel;
|
2026-02-10 11:03:29 +00:00
|
|
|
[SerializeField] private Button ResumeButton;
|
|
|
|
|
[SerializeField] private Button ExitButton;
|
|
|
|
|
[SerializeField] private Button ReTryButton;
|
|
|
|
|
|
2026-02-10 08:18:34 +00:00
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
if (instance == null)
|
|
|
|
|
{
|
|
|
|
|
instance = this;
|
|
|
|
|
DontDestroyOnLoad(gameObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
2026-02-10 11:03:29 +00:00
|
|
|
if (pausePanel != null)
|
|
|
|
|
{
|
|
|
|
|
pausePanel.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-10 08:18:34 +00:00
|
|
|
GameManager.instance.OnReplayCountChanged += UpdateLivesText;
|
|
|
|
|
GameManager.instance.OnTimeChanged += UpdateTimeText;
|
|
|
|
|
GameManager.instance.OnEnterLevel += ShowLevelUI;
|
|
|
|
|
GameManager.instance.OnExitLevel += HideLevelUI;
|
|
|
|
|
GameManager.instance.OnPressPause += OnPressPause;
|
2026-02-10 11:03:29 +00:00
|
|
|
|
|
|
|
|
ResumeButton.onClick.AddListener(GameManager.instance.TogglePause);
|
|
|
|
|
ExitButton.onClick.AddListener(GameManager.instance.ExitLevel);
|
|
|
|
|
ReTryButton.onClick.AddListener(GameManager.instance.Retry);
|
2026-02-10 08:18:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
GameManager.instance.OnReplayCountChanged -= UpdateLivesText;
|
|
|
|
|
GameManager.instance.OnTimeChanged -= UpdateTimeText;
|
|
|
|
|
GameManager.instance.OnEnterLevel -= ShowLevelUI;
|
|
|
|
|
GameManager.instance.OnExitLevel -= HideLevelUI;
|
|
|
|
|
GameManager.instance.OnPressPause -= OnPressPause;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateLivesText(int lives)
|
|
|
|
|
{
|
|
|
|
|
livesText.text = "X "+ lives;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateTimeText(int time)
|
|
|
|
|
{
|
|
|
|
|
timeText.text = time.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnPressPause(bool pause)
|
|
|
|
|
{
|
|
|
|
|
pausePanel.SetActive(pause);
|
2026-02-10 11:03:29 +00:00
|
|
|
EventSystem.current.SetSelectedGameObject(ResumeButton.gameObject);
|
2026-02-10 08:18:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowLevelUI()
|
|
|
|
|
{
|
|
|
|
|
timeText.gameObject.SetActive(true);
|
|
|
|
|
livesText.gameObject.SetActive(true);
|
|
|
|
|
pausePanel.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HideLevelUI()
|
|
|
|
|
{
|
|
|
|
|
timeText.gameObject.SetActive(false);
|
|
|
|
|
livesText.gameObject.SetActive(false);
|
|
|
|
|
pausePanel.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
}
|