76 lines
2.0 KiB
C#
76 lines
2.0 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
/// <summary>
|
|
/// Финальный экран победы при успешном завершении игры на 2-м уровне.
|
|
/// </summary>
|
|
public class FinalVictoryUI : MonoBehaviour
|
|
{
|
|
private static FinalVictoryUI _instance;
|
|
public static FinalVictoryUI Instance
|
|
{
|
|
get
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
_instance = Object.FindAnyObjectByType<FinalVictoryUI>(FindObjectsInactive.Include);
|
|
}
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
[Header("Корневая панель")]
|
|
[SerializeField] private GameObject victoryPanelRoot;
|
|
|
|
public bool IsOpen => victoryPanelRoot != null && victoryPanelRoot.activeInHierarchy;
|
|
|
|
[Header("Кнопки")]
|
|
[SerializeField] private Button restartButton;
|
|
[SerializeField] private Button mainMenuButton;
|
|
|
|
private void Awake()
|
|
{
|
|
_instance = this;
|
|
if (victoryPanelRoot == null)
|
|
victoryPanelRoot = gameObject;
|
|
|
|
if (restartButton != null)
|
|
{
|
|
restartButton.onClick.RemoveAllListeners();
|
|
restartButton.onClick.AddListener(OnRestartGameClicked);
|
|
}
|
|
|
|
if (mainMenuButton != null)
|
|
{
|
|
mainMenuButton.onClick.RemoveAllListeners();
|
|
mainMenuButton.onClick.AddListener(OnMainMenuClicked);
|
|
}
|
|
}
|
|
|
|
public void ShowVictoryScreen()
|
|
{
|
|
if (!gameObject.activeSelf) gameObject.SetActive(true);
|
|
if (victoryPanelRoot != null)
|
|
victoryPanelRoot.SetActive(true);
|
|
|
|
Time.timeScale = 0f;
|
|
Cursor.lockState = CursorLockMode.None;
|
|
Cursor.visible = true;
|
|
|
|
GameAudioSynthesizer.PlaySuccessChime();
|
|
}
|
|
|
|
public void OnRestartGameClicked()
|
|
{
|
|
Time.timeScale = 1f;
|
|
SceneManager.LoadScene("SampleScene"); // Начать с 1-го уровня
|
|
}
|
|
|
|
public void OnMainMenuClicked()
|
|
{
|
|
Time.timeScale = 1f;
|
|
SceneManager.LoadScene("MainMenu");
|
|
}
|
|
}
|