refactor: use PlayDelayed API for audio delay and add Stop by ID support

- Replace PlayAfterDelay coroutine with AudioSource.PlayDelayed
- Add Stop(audioId) public API
- Add startWithMusic toggle
- Clean up namespace and debug macros
This commit is contained in:
2026-04-17 11:20:17 +08:00
parent 0fdd76022d
commit 63c5f6766c
10 changed files with 291 additions and 36 deletions
@@ -10,8 +10,12 @@ namespace OCES.Audio
public class AudioSystem : MonoBehaviour
{
public static AudioSystem Instance { get; private set; }
public bool startWithMusic;
public ConsoleLogLevel logLevel;
// ReSharper disable once MemberCanBePrivate.Global
public IReadOnlyDictionary<Type, Enum> ActiveStates { get; private set; }
public enum ConsoleLogLevel { Off, Log, Warning, Error } //TODO 实现这个功能
const string k_audioConfigPath = "AudioData";
const string k_audioResourcePath = "Audios";
@@ -170,6 +174,11 @@ namespace OCES.Audio
}
}
public void Stop(uint audioId)
{
this.m_sfxSystem.Stop(audioId);
}
// ─────────────────────────────────────────────
// 初始化
// ─────────────────────────────────────────────
@@ -244,7 +253,10 @@ namespace OCES.Audio
{
// ── 启动默认音乐与环境音 ──
// 触发一次初始状态,让音乐系统从默认状态开始匹配
SetState(GameState.Home);
if (this.startWithMusic)
{
SetState(GameState.Home);
}
}
AudioObject ResolveSwitchContainer(AudioObject switchContainer)