Danro/Assets/Scripts/UI/PauseMenu.cs
Danil Iarosh 2f2d100eae feat(inputs): remove obsolete COM input system and update dependencies
- Removed deprecated ButtonPinMapping enum and related COM input classes- Updated ComInputToInputSystemAdapter with improved binding logic- Refactored GameManager to use new globals prefab path
- Enhanced GameEndUIController with event system focus management
- Modified Globals prefab to use pin-based input bindings
- Cleaned up obsolete COM system wrapper and native wrapper classes
- Adjusted input adapter to support pin bindings over action bindings
- Updated manufacturer name in virtual gamepad description
2025-11-04 17:06:51 +03:00

139 lines
4.7 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 System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.InputSystem;
using UnityEngine.EventSystems;
using RR.Game2D.Core.Managers;
namespace RR.Common.UI
{
public class PauseMenu : MonoBehaviour
{
[Header("Управление")]
[SerializeField] private InputActionReference close;
[Header("UI")]
[SerializeField] private CanvasGroup panel;
[SerializeField] private Button resumeButton;
[SerializeField] private Button quitButton;
[Header("Связь с другими элементами")]
[SerializeField] private GameEndUIController bannerController;
//[SerializeField] private Button restartButton;
//[SerializeField] private KeyCode toggleKey = KeyCode.Escape; // Esc
private bool isActive = true;
private void OnEnable()
{
if (GameManager.Instance != null)
GameManager.Instance.PauseStateChanged += HandlePauseChanged;
bannerController.WinBannerShown += (f) => { isActive = false; };
bannerController.LoseBannerShown += (f) => { isActive = false; };
bannerController.BannerDismissed += () => { isActive = true; };
}
private void OnDisable()
{
if (GameManager.Instance != null)
GameManager.Instance.PauseStateChanged -= HandlePauseChanged;
}
private void Awake()
{
if (resumeButton) resumeButton.onClick.AddListener(OnResumeClicked);
if (quitButton) quitButton.onClick.AddListener(OnQuitClicked);
//if (restartButton) restartButton.onClick.AddListener(OnRestartClicked);
// Изначально скрыто
SetVisible(false, instant: true);
}
private void Update()
{
if (close.action.WasPressedThisFrame() && !GameManager.Instance.IsPaused)
GameManager.Instance.TogglePause();
}
/// <summary>
/// Обработка события паузы
/// </summary>
/// <param name="paused">Ставить ли на паузу</param>
private void HandlePauseChanged(bool paused)
{
if (!isActive) return;
if (paused)
{
EventSystem.current.firstSelectedGameObject = resumeButton.gameObject;
EventSystem.current.SetSelectedGameObject(resumeButton.gameObject);
}
SetVisible(paused);
}
/// <summary>
/// Метод для изменения отображения
/// </summary>
/// <param name="visible">Отображать ли меню паузы</param>
/// <param name="instant">Постоянно или нет</param>
private void SetVisible(bool visible, bool instant = false)
{
if (!panel) return;
panel.interactable = visible;
panel.blocksRaycasts = visible;
if (instant)
{
panel.alpha = visible ? 1f : 0f;
}
else
{
StopAllCoroutines();
StartCoroutine(Fade(panel, visible ? 1f : 0f, 0.15f));
}
}
/// <summary>
/// Метод для плавного изменения видимости
/// </summary>
/// <param name="cg">Группа холстов</param>
/// <param name="target">Целевое значение альфа-канала</param>
/// <param name="duration">Продолжительность перехода</param>
private IEnumerator Fade(CanvasGroup cg, float target, float duration)
{
float start = cg.alpha;
float t = 0f;
while (t < duration)
{
t += Time.unscaledDeltaTime;
cg.alpha = Mathf.Lerp(start, target, t / duration);
yield return null;
}
cg.alpha = target;
}
/// <summary>
/// Метод для возобновления игры
/// </summary>
public void OnResumeClicked() => GameManager.Instance.SetPause(false);
//public void OnRestartClicked()
//{
// GameManager.Instance.SetPause(false);
// GameManager.Instance.ResetLevel();
//}
/// <summary>
/// Метод для выхода в главное меню
/// </summary>
public void OnQuitClicked()
{
GameManager.Instance.SetPause(false);
GameManager.Instance.LoadScene("MainMenu", false);
}
}
}