какашки мне в кармашки
This commit is contained in:
1 parent
7fba61f7a0
commit
cbda26dfc0
335 files changed
+51926
-7266
No files matched your search
@@ -0,0 +1,102 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class DeathScreenUI : MonoBehaviour
|
||||
{
|
||||
public static DeathScreenUI Instance { get; private set; }
|
||||
|
||||
[Header("Панель смерти")]
|
||||
public GameObject deathPanel;
|
||||
public CanvasGroup canvasGroup;
|
||||
|
||||
[Header("Кнопки")]
|
||||
public Button restartButton;
|
||||
public Button mainMenuButton;
|
||||
|
||||
[Header("Настройки")]
|
||||
public float fadeDuration = 0.8f;
|
||||
public string mainMenuSceneName = "MainMenu";
|
||||
|
||||
private bool isShown = false;
|
||||
public bool IsShown => isShown;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null) Instance = this;
|
||||
|
||||
if (deathPanel != null)
|
||||
{
|
||||
deathPanel.SetActive(false);
|
||||
}
|
||||
|
||||
if (restartButton != null)
|
||||
{
|
||||
restartButton.onClick.AddListener(RestartGame);
|
||||
}
|
||||
|
||||
if (mainMenuButton != null)
|
||||
{
|
||||
mainMenuButton.onClick.AddListener(ReturnToMainMenu);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Показывает экран смерти с плавным затемнением и открывает курсор
|
||||
/// </summary>
|
||||
public void ShowDeathScreen()
|
||||
{
|
||||
if (isShown) return;
|
||||
isShown = true;
|
||||
|
||||
if (deathPanel != null)
|
||||
{
|
||||
deathPanel.SetActive(true);
|
||||
StartCoroutine(FadeInRoutine());
|
||||
}
|
||||
|
||||
// Разблокируем курсор для кликов по кнопкам
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
|
||||
private IEnumerator FadeInRoutine()
|
||||
{
|
||||
if (canvasGroup != null)
|
||||
{
|
||||
canvasGroup.alpha = 0f;
|
||||
float elapsed = 0f;
|
||||
while (elapsed < fadeDuration)
|
||||
{
|
||||
elapsed += Time.unscaledDeltaTime;
|
||||
canvasGroup.alpha = Mathf.Clamp01(elapsed / fadeDuration);
|
||||
yield return null;
|
||||
}
|
||||
canvasGroup.alpha = 1f;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перезапускает текущую игровую сцену
|
||||
/// </summary>
|
||||
public void RestartGame()
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
Scene currentScene = SceneManager.GetActiveScene();
|
||||
SceneManager.LoadScene(currentScene.name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает игрока в главное меню
|
||||
/// </summary>
|
||||
public void ReturnToMainMenu()
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
SceneManager.LoadScene(mainMenuSceneName);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user