Files
ichni_Official/Assets/Scripts/Manager/GameManager.cs

137 lines
5.1 KiB
C#
Raw Normal View History

2025-06-03 02:42:28 -04:00
using System;
using System.Collections;
using System.Collections.Generic;
2026-03-14 03:13:10 -04:00
using System.Linq;
2025-06-03 02:42:28 -04:00
using Ichni.RhythmGame;
2025-07-08 14:28:40 -04:00
using Ichni.RhythmGame.UI;
2025-06-03 02:42:28 -04:00
using Sirenix.OdinInspector;
2026-03-14 03:13:10 -04:00
using SLSUtilities.General;
2025-06-03 02:42:28 -04:00
using UnityEngine;
2025-07-21 05:42:20 -04:00
using UnityEngine.SceneManagement;
2025-08-11 14:04:06 -04:00
using UnityEngine.Serialization;
2025-06-03 02:42:28 -04:00
namespace Ichni
{
2026-03-14 03:13:10 -04:00
public partial class GameManager : Singleton<GameManager>, ISongTimeProvider
2025-06-03 02:42:28 -04:00
{
2026-03-14 03:13:10 -04:00
[FormerlySerializedAs("audioManager")] public SongPlayer songPlayer;
2025-06-03 02:42:28 -04:00
public CameraManager cameraManager;
2025-08-11 14:04:06 -04:00
[FormerlySerializedAs("inputManager")] public NoteJudgeManager noteJudgeManager;
2025-06-03 02:42:28 -04:00
public BackgroundSetter backgroundSetter;
public BackgroundController backgroundController;
public VariablesContainer variablesContainer;
public ProjectLoader projectLoader;
public PlayingRecorder playingRecorder;
public BeatmapContainer beatmapContainer;
public CommandScripts commandScripts;
public ProjectInformation projectInformation;
public SongInformation songInformation;
2026-03-14 03:13:10 -04:00
public List<TimeDurationSubmodule> timeDurations;
public AnimationManager animationManager;
public TrackManager trackManager;
2025-07-21 05:42:20 -04:00
public NoteManager noteManager;
2025-06-03 02:42:28 -04:00
public BasePrefabsCollection basePrefabs;
2025-07-10 08:42:30 -04:00
public Dictionary<string, CustomPrefabsCollection> customPrefabs;
2025-06-03 02:42:28 -04:00
2026-03-19 14:14:28 -04:00
public List<IHaveTransformSubmodule> activeTransformSubmodules = new List<IHaveTransformSubmodule>();
public List<IHaveColorSubmodule> activeColorSubmodules = new List<IHaveColorSubmodule>();
public List<IHaveDirtyMarkSubmodule> activeDirtyMarkSubmodules = new List<IHaveDirtyMarkSubmodule>();
2026-06-05 04:45:57 -04:00
public ElementUpdateScheduler updateScheduler;
2026-03-19 14:14:28 -04:00
2025-07-08 14:28:40 -04:00
[Title("UI")]
2025-06-03 02:42:28 -04:00
public Canvas judgeHintCanvas;
2025-07-08 14:28:40 -04:00
public GameUICanvas gameUICanvas;
public GameLoadingCanvas gameLoadingCanvas;
public SummaryPageCanvas summaryPageCanvas;
2026-03-14 03:13:10 -04:00
public float SongTime => songPlayer.isStarting ? 0 :
songPlayer.songTimeSegment - songInformation.offset - (SettingsManager.instance.gameSettings.beatmapOffset / 1000f);
public bool IsPlaying => songPlayer != null && songPlayer.isPlaying;
2025-08-11 14:04:06 -04:00
2025-06-03 02:42:28 -04:00
public bool isDebugging;
2026-03-14 03:13:10 -04:00
protected override void Awake()
2025-06-03 02:42:28 -04:00
{
2026-03-14 03:13:10 -04:00
base.Awake();
CoreServices.TimeProvider = this;
timeDurations = new List<TimeDurationSubmodule>();
2025-06-03 02:42:28 -04:00
playingRecorder = new PlayingRecorder();
playingRecorder.Initialize();
2026-06-05 04:45:57 -04:00
updateScheduler = new ElementUpdateScheduler();
CoreServices.UpdateScheduler = updateScheduler;
2025-06-03 02:42:28 -04:00
}
private void Start()
{
2025-08-11 14:04:06 -04:00
basePrefabs.PrepareAudios();
2025-06-03 02:42:28 -04:00
projectLoader.TestLoad();
}
2026-03-14 03:13:10 -04:00
private void Update()
{
2026-06-05 04:45:57 -04:00
updateScheduler.TickEarly(SongTime);
2026-03-14 03:13:10 -04:00
}
private void LateUpdate()
{
2026-06-05 04:45:57 -04:00
updateScheduler.TickLate();
2026-03-14 03:13:10 -04:00
}
2025-06-03 02:42:28 -04:00
}
2025-07-21 05:42:20 -04:00
public partial class GameManager
{
/// <summary>
/// 将当前演奏结果写入独立的游戏记录存档。
/// <para>由 SongPlayer 在实际歌曲结束后、打开 Summary 前调用。</para>
/// <para>剧情树、选项和 Yarn 变量仍由 <see cref="StorySaveModule"/> 单独管理。</para>
/// 当前 Difficulty 的 Chart Revision 会一并传入,从而在谱面改版时只清除不可比较的单谱面成绩。
/// </summary>
public bool SaveCurrentPlayRecord()
{
if (GameSaveManager.instance == null || GameSaveManager.instance.SongSaveModule == null)
{
Debug.LogWarning("Cannot save play record because SongSaveModule is not initialized.");
return false;
}
if (InformationTransistor.instance == null ||
InformationTransistor.instance.song == null ||
InformationTransistor.instance.difficulty == null)
{
Debug.LogWarning("Cannot save play record because the selected song or difficulty is missing.");
return false;
}
return GameSaveManager.instance.SongSaveModule.RecordPlayResult(
InformationTransistor.instance.song.songName,
InformationTransistor.instance.difficulty.saveDifficultyId,
InformationTransistor.instance.difficulty.GetChartRevision(),
playingRecorder);
}
2025-07-21 05:42:20 -04:00
public static void RestartGame()
{
// 保留 InformationTransistor 中的歌曲和返回目标,使教程与普通歌曲的重开都回到正确页面。
2025-07-21 05:42:20 -04:00
SceneManager.LoadScene("GameScene");
Time.timeScale = 1f; // 确保重启时时间缩放恢复正常
}
public static void ReturnToMenu()
{
Time.timeScale = 1f; // 确保返回时时间缩放恢复正常
// 返回目标已在进入 GameScene 时写入 InformationTransistor这里不再写互斥布尔值。
SceneManager.LoadScene("MenuScene");
2025-07-21 05:42:20 -04:00
}
}
}