Files
ichni_Official/Assets/Scripts/Menu/InformationTransistor.cs
SoulliesOfficial 810d019619 剧情+对话完善
2026-07-21 15:24:42 -04:00

119 lines
4.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 Ichni.Story;
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;
/// <summary>
/// 由剧情 SongBlock 发起的单次选曲上下文。它是运行时路由数据,不属于玩家存档;
/// 仅用于校验目标歌曲、决定返回页面并还原剧情树浏览位置。
/// </summary>
[System.NonSerialized] public StorySongEntryContext storySongEntryContext = new StorySongEntryContext();
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 返回目标。
if (PrepareGameLaunch(chapter, song, difficulty, MenuReturnDestination.None))
{
// 只有玩家真正确认“进入游戏”且命中剧情目标歌曲时,才完成对应 SongBlock。
// 单纯从剧情打开选曲、浏览其它歌曲或返回菜单都不会写入剧情进度。
StoryManager.instance?.HandleSongSelectionConfirmed(chapter, song);
}
}
/// <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;
// “确认进入游戏”是歌曲尝试的统一边界。无论入口来自普通选曲、Story SongBlock 或教程,
// 都由 SongSaves 记录这一次尝试StoryTree 会在构建/返回时据此同步 SongBlock 完成状态。
GameSaveManager.instance?.SongSaveModule?.MarkSongTried(song.songName);
return true;
}
/// <summary>
/// 由现有选曲过场在真正激活 GameScene 前设置返回目标。
/// </summary>
public void SetMenuReturnDestination(MenuReturnDestination returnDestination)
{
menuReturnDestination = returnDestination;
}
/// <summary>
/// MenuScene 已依据返回目标完成恢复后调用。
/// 只清除一次性路由,不清除歌曲与难度,以免当前 UI 的运行时缓存被意外破坏。
/// </summary>
public void ClearMenuReturnDestination()
{
menuReturnDestination = MenuReturnDestination.None;
}
}
}