Kursach_StealthAction/Assets/Scripts/FinalVictoryUI.cs
2026-10-23 15:44:09 +03:00

76 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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();
}
private void OnRestartGameClicked()
{
Time.timeScale = 1f;
SceneManager.LoadScene("SampleScene"); // Начать с 1-го уровня
}
private void OnMainMenuClicked()
{
Time.timeScale = 1f;
SceneManager.LoadScene("MainMenu");
}
}