Files
ichni_Official/Assets/Scripts/Menu/InformationTransistor.cs

103 lines
3.5 KiB
C#
Raw Normal View History

2025-06-03 02:42:28 -04:00
using System.Collections;
using System.Collections.Generic;
using AK.Wwise;
2025-07-21 05:42:20 -04:00
using Ichni.Menu;
2025-06-03 02:42:28 -04:00
using UnityEngine;
2025-07-21 05:42:20 -04:00
using UnityEngine.Serialization;
2025-06-03 02:42:28 -04:00
namespace Ichni
{
/// <summary>
/// GameScene 返回 MenuScene 后应恢复的页面。
/// 该枚举替代互斥的布尔标记,避免普通歌曲与教程返回状态同时残留。
/// </summary>
public enum MenuReturnDestination
{
None,
SongSelection,
Story
}
2025-06-03 02:42:28 -04:00
public class InformationTransistor : MonoBehaviour
{
public static InformationTransistor instance;
/// <summary>
/// 当前游戏运行结束后MenuScene 应恢复的唯一目标页面。
/// 运行期间保存在 DontDestroyOnLoad 对象中,不写入玩家存档。
/// </summary>
public MenuReturnDestination menuReturnDestination;
2025-07-21 05:42:20 -04:00
public ChapterSelectionUnit chapter;
public SongItemData song;
public DifficultyData difficulty;
2025-08-11 14:04:06 -04:00
public float songLength;
public float bpm;
2025-06-03 02:42:28 -04:00
public Switch chapterSwitch;
2025-07-21 05:42:20 -04:00
public Switch songSwitch;
2025-06-03 02:42:28 -04:00
2025-06-14 14:42:49 -04:00
private void Awake()
2025-06-03 02:42:28 -04:00
{
2025-06-14 14:42:49 -04:00
if (instance == null)
2025-06-03 02:42:28 -04:00
{
instance = this;
DontDestroyOnLoad(gameObject);
menuReturnDestination = MenuReturnDestination.None;
2025-06-03 02:42:28 -04:00
}
2025-06-14 14:42:49 -04:00
else
{
Destroy(gameObject);
}
2025-06-03 02:42:28 -04:00
}
2025-07-21 05:42:20 -04:00
public void SetInformation(ChapterSelectionUnit chapter,
SongItemData song, DifficultyData difficulty)
2025-06-03 02:42:28 -04:00
{
// 保留旧入口,供现有选曲流程在播放过场前预先写入歌曲信息。
// 真正进入 GameScene 时MenuManager.EnterGame 会补充 SongSelection 返回目标。
PrepareGameLaunch(chapter, song, difficulty, MenuReturnDestination.None);
}
/// <summary>
/// 统一准备一次 GameScene 运行所需的上下文。
/// 普通选曲和 TutorialBlock 都必须通过此入口写入,防止章节、歌曲、难度与返回目标来自不同旧运行。
/// </summary>
public bool PrepareGameLaunch(ChapterSelectionUnit chapter, SongItemData song,
DifficultyData difficulty, MenuReturnDestination returnDestination)
{
if (chapter == null || song == null || difficulty == null)
{
Debug.LogWarning("[InformationTransistor] 缺少章节、歌曲或难度,无法准备 GameScene 上下文。");
return false;
}
2025-07-21 05:42:20 -04:00
this.chapter = chapter;
this.song = song;
this.difficulty = difficulty;
chapterSwitch = chapter.chapterSwitch;
songSwitch = song.songSwitch;
menuReturnDestination = returnDestination;
return true;
}
/// <summary>
/// 由现有选曲过场在真正激活 GameScene 前设置返回目标。
/// </summary>
public void SetMenuReturnDestination(MenuReturnDestination returnDestination)
{
menuReturnDestination = returnDestination;
}
/// <summary>
/// MenuScene 已依据返回目标完成恢复后调用。
/// 只清除一次性路由,不清除歌曲与难度,以免当前 UI 的运行时缓存被意外破坏。
/// </summary>
public void ClearMenuReturnDestination()
{
menuReturnDestination = MenuReturnDestination.None;
2025-06-03 02:42:28 -04:00
}
}
}