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