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