Passion & UI
This commit is contained in:
121
Assets/Scripts/MainGame/UI/PlayerUI/PausePage/PauseUIPage.cs
Normal file
121
Assets/Scripts/MainGame/UI/PlayerUI/PausePage/PauseUIPage.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using System.Collections.Generic;
|
||||
using Cielonos.Core.SceneManagement;
|
||||
using DG.Tweening;
|
||||
using SLSUtilities.General;
|
||||
using SLSUtilities.UI;
|
||||
using SLSUtilities.WwiseAssistance;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cielonos.MainGame.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// 暂停界面页面。
|
||||
/// <para>
|
||||
/// 打开时暂停游戏(<c>Time.timeScale = 0</c>),
|
||||
/// 关闭时恢复游戏。
|
||||
/// 提供三个按钮:继续游戏、打开设置、返回标题界面。
|
||||
/// 返回标题界面时会弹出 <see cref="ConfirmUIPage"/> 二次确认。
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public class PauseUIPage : UIPageBase
|
||||
{
|
||||
// ──────────────────── 按钮引用 ────────────────────
|
||||
|
||||
[FormerlySerializedAs("continueButton")]
|
||||
[Header("Buttons")]
|
||||
[SerializeField] private Button resumeButton;
|
||||
[SerializeField] private Button settingsButton;
|
||||
[SerializeField] private Button returnToMenuButton;
|
||||
|
||||
// ──────────────────── 配置 ────────────────────────
|
||||
|
||||
[Header("Scene")]
|
||||
[Tooltip("标题界面的场景名称,通过 SceneBus 加载。")]
|
||||
[SerializeField] private string titleSceneName = "Menu";
|
||||
|
||||
// ──────────────────── 生命周期 ────────────────────
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
resumeButton.onClick.AddListener(OnContinueClicked);
|
||||
settingsButton.onClick.AddListener(OnSettingsClicked);
|
||||
returnToMenuButton.onClick.AddListener(OnReturnToTitleClicked);
|
||||
}
|
||||
|
||||
public override void Open()
|
||||
{
|
||||
if (IsOpen) return;
|
||||
IsOpen = true;
|
||||
Time.timeScale = 0f;
|
||||
UIPageManager.Instance.RegisterPage(this);
|
||||
EventSystem.current?.SetSelectedGameObject(null);
|
||||
gameObject.SetActive(true);
|
||||
canvasGroup.interactable = true;
|
||||
canvasGroup.DOFade(1f, 0.3f).From(0f).SetUpdate(true)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
OnPageOpened();
|
||||
}).Play();
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
if (!IsOpen) return;
|
||||
IsOpen = false;
|
||||
UIPageManager.Instance.UnregisterPage(this);
|
||||
canvasGroup.DOFade(0f, 0.3f).From(1f).SetUpdate(true)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
canvasGroup.interactable = false;
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
OnPageClosed();
|
||||
Time.timeScale = 1f;
|
||||
}).Play();
|
||||
}
|
||||
|
||||
// ──────────────────── 按钮回调 ────────────────────
|
||||
|
||||
private void OnContinueClicked()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void OnSettingsClicked()
|
||||
{
|
||||
PlayerCanvas.SettingsUIPage.Open();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点击"返回主菜单"按钮时,弹出确认弹窗而非直接切换场景。
|
||||
/// </summary>
|
||||
private void OnReturnToTitleClicked()
|
||||
{
|
||||
ConfirmUIPage.Show(new ConfirmPageConfig
|
||||
{
|
||||
Title = "ConfirmReturnToMenu_Title".Localize("UI"),
|
||||
Description = "ConfirmReturnToMenu_Desc".Localize("UI"),
|
||||
Buttons = new List<ConfirmButtonConfig>
|
||||
{
|
||||
new("Confirm".Localize("UI"), ReturnToMenu),
|
||||
new("Cancel".Localize("UI"))
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户确认后执行的返回主菜单逻辑。
|
||||
/// </summary>
|
||||
private void ReturnToMenu()
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
AudioManager.Instance.backgroundMusicManager.TransitionToNextScene();
|
||||
UIPageManager.Instance.CloseAllPages();
|
||||
SceneBus.LoadScene(titleSceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b190c38fdc79d24b8c7cd550c838030
|
||||
Reference in New Issue
Block a user