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

103 lines
3.5 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 System.Collections.Generic;
using AK.Wwise;
using Ichni.Menu;
using UnityEngine;
using UnityEngine.Serialization;
namespace Ichni
{
/// <summary>
/// GameScene 返回 MenuScene 后应恢复的页面。
/// 该枚举替代互斥的布尔标记,避免普通歌曲与教程返回状态同时残留。
/// </summary>
public enum MenuReturnDestination
{
None,
SongSelection,
Story
}
public class InformationTransistor : MonoBehaviour
{
public static InformationTransistor instance;
/// <summary>
/// 当前游戏运行结束后MenuScene 应恢复的唯一目标页面。
/// 运行期间保存在 DontDestroyOnLoad 对象中,不写入玩家存档。
/// </summary>
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);
}
/// <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;
}
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;
}
}
}