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

128 lines
4.3 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>();
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();
}
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()
{
if (!songPlayer.isUpdating) return;
foreach (var timeDuration in timeDurations)
{
timeDuration?.DetectAndSwitchActiveState(SongTime);
}
animationManager.ManualUpdate(SongTime);
trackManager.ManualUpdate(SongTime);
noteManager.ManualUpdate(SongTime);
}
private void LateUpdate()
{
if (!songPlayer.isUpdating) return;
trackManager.ManualLateUpdate(SongTime);
noteManager.ManualLateUpdate(SongTime);
2026-03-19 14:14:28 -04:00
for(int i = 0; i < activeColorSubmodules.Count; i++)
{
activeColorSubmodules[i].UpdateColor(true);
}
for(int i = 0; i < activeTransformSubmodules.Count; i++)
{
activeTransformSubmodules[i].UpdateTransform(true);
}
for(int i = 0; i < activeDirtyMarkSubmodules.Count; i++)
{
2026-03-21 12:12:12 -04:00
activeDirtyMarkSubmodules[i]?.dirtyMarkSubmodule?.ExecuteDeferredRefresh();
2026-03-19 14:14:28 -04:00
}
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
{
public static void RestartGame()
{
SceneManager.LoadScene("GameScene");
Time.timeScale = 1f; // 确保重启时时间缩放恢复正常
}
public static void ReturnToMenu()
{
2025-09-06 21:58:48 -04:00
//InformationTransistor.instance.isReturnedFromGame = true;
2025-07-21 05:42:20 -04:00
SceneManager.LoadScene("MenuScene");
Time.timeScale = 1f; // 确保返回时时间缩放恢复正常
}
}
2025-06-03 02:42:28 -04:00
}