多轮审查和修复

This commit is contained in:
2026-05-12 15:34:08 +08:00
parent f55d2a57c3
commit ebbbb7332e
805 changed files with 838724 additions and 1905 deletions

View File

@@ -30,19 +30,23 @@ namespace BaseGames.Audio
private MusicState _musicState = MusicState.Exploration;
private string _currentRegion = string.Empty;
private readonly CompositeDisposable _subscriptions = new();
private void Awake()
{
Debug.Assert(_config != null, "[BGMController] _config 未赋值,请在 Inspector 中指定 AudioConfigSO。", this);
}
private void OnEnable()
{
if (_onBossFightToggled != null) _onBossFightToggled.OnEventRaised += OnBossFightToggled;
if (_onRegionEntered != null) _onRegionEntered.OnEventRaised += OnRegionEntered;
if (_onGameStateChanged != null) _onGameStateChanged.OnEventRaised += HandleStateChanged;
_onBossFightToggled?.Subscribe(OnBossFightToggled).AddTo(_subscriptions);
_onRegionEntered?.Subscribe(OnRegionEntered).AddTo(_subscriptions);
_onGameStateChanged?.Subscribe(HandleStateChanged).AddTo(_subscriptions);
}
private void OnDisable()
{
if (_onBossFightToggled != null) _onBossFightToggled.OnEventRaised -= OnBossFightToggled;
if (_onRegionEntered != null) _onRegionEntered.OnEventRaised -= OnRegionEntered;
if (_onGameStateChanged != null) _onGameStateChanged.OnEventRaised -= HandleStateChanged;
_subscriptions.Clear();
}
private void OnBossFightToggled(bool started)
@@ -50,7 +54,7 @@ namespace BaseGames.Audio
if (started)
{
_musicState = MusicState.Boss;
var clip = _config != null ? _config.GetBossBGM(_currentRegion) : null;
var clip = _config.GetBossBGM(_currentRegion);
_audioManager.PlayBGM(clip, fadeOutDur: 1f, fadeInDur: 0.5f);
_audioManager.TransitionToSnapshot("BossFight", 0.5f);
}
@@ -63,9 +67,9 @@ namespace BaseGames.Audio
private IEnumerator PlayVictoryThenRestore()
{
_musicState = MusicState.Victory;
_audioManager.PlayBGM(_config != null ? _config.VictoryStingBGM : null,
_audioManager.PlayBGM(_config.VictoryStingBGM,
fadeOutDur: 0.3f, fadeInDur: 0.1f);
float dur = _config != null ? _config.VictoryStingDuration : 4f;
float dur = _config.VictoryStingDuration;
yield return new WaitForSecondsRealtime(dur);
_musicState = MusicState.Exploration;
OnRegionEntered(_currentRegion);
@@ -78,16 +82,15 @@ namespace BaseGames.Audio
_currentRegion = regionId;
if (_musicState == MusicState.Exploration)
{
var clip = _config != null ? _config.GetZoneBGM(regionId) : null;
var clip = _config.GetZoneBGM(regionId);
_audioManager.PlayBGM(clip, fadeOutDur: 1f, fadeInDur: 1f);
}
}
private void HandleStateChanged(GameStateId state)
{
// ⚠️ GameStateId 是 struct不能用 switch使用 if/else + GameStates 常量
if (state == GameStates.MainMenu)
_audioManager.PlayBGM(_config != null ? _config.MainMenuBGM : null,
_audioManager.PlayBGM(_config.MainMenuBGM,
fadeOutDur: 0.5f, fadeInDur: 1.0f);
else if (state == GameStates.Paused)
_audioManager.TransitionToSnapshot("Paused", 0.2f);