- Increased SFX pool size from 8 to 16 in AudioManager - Enabled preloadAudioData for multiple SFX files - Removed unused VisualScripting import from Checkpoint script - Reordered using statements in several scripts for consistency - Added CoinCollectible component to Coin prefab with pickup effects - Updated sorting layers and mesh LOD settings in Coin prefabs - Fixed typo in Interfaces.cs: optionaAttachPoint to optionalAttachPoint - Modified AddCoin method to accept count parameter and handle coin overflow - Moved projectile scripts (BasicProjectile, EnemyBasicProjectile, PhysicsProjectile, PickableProjectile) - Cleaned up unused namespaces and imports across various scripts
121 lines
3.9 KiB
C#
121 lines
3.9 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.InputSystem;
|
|
|
|
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;
|
|
//[SerializeField] private Button restartButton;
|
|
//[SerializeField] private KeyCode toggleKey = KeyCode.Escape; // Esc
|
|
|
|
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 OnEnable()
|
|
{
|
|
if (GameManager.Instance != null)
|
|
GameManager.Instance.PauseStateChanged += HandlePauseChanged;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (GameManager.Instance != null)
|
|
GameManager.Instance.PauseStateChanged -= HandlePauseChanged;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (close.action.WasPressedThisFrame())
|
|
GameManager.Instance.TogglePause();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Обработка события паузы
|
|
/// </summary>
|
|
/// <param name="paused">Ставить ли на паузу</param>
|
|
private void HandlePauseChanged(bool paused)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
} |