feat: music callback
This commit is contained in:
@@ -29,7 +29,6 @@ namespace OCES.Audio
|
||||
// ─────────────────────────────────────────────
|
||||
|
||||
public event Action<uint> OnBeat;
|
||||
|
||||
public event Action<uint> OnBar;
|
||||
public event Action<uint> OnGrid;
|
||||
|
||||
@@ -196,10 +195,13 @@ namespace OCES.Audio
|
||||
EnumIds.RegisterAllGameState();
|
||||
|
||||
ActiveStates = new Dictionary<Type, Enum>();
|
||||
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
// ── 启动默认音乐与环境音 ──
|
||||
// 触发一次初始状态,让音乐系统从默认状态开始匹配
|
||||
//SetState(GameState.Home);
|
||||
SetState(GameState.Home);
|
||||
}
|
||||
|
||||
AudioObject ResolveSwitchContainer(AudioObject switchContainer)
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OCES.Audio
|
||||
|
||||
public void Restart(MusicContainer container, float inheritedBpm, double dspTime)
|
||||
{
|
||||
Debug.Log($"[BeatClock] Restart called, container={container.Id}, bpm={container.Bpm}, inherited={inheritedBpm}");
|
||||
//Debug.Log($"[BeatClock] Restart called, container={container.Id}, bpm={container.Bpm}, inherited={inheritedBpm}");
|
||||
|
||||
StopAll();
|
||||
this.m_blendError = this.m_stopped = false;
|
||||
@@ -69,21 +69,15 @@ namespace OCES.Audio
|
||||
while (true)
|
||||
{
|
||||
double nextTime = this.m_startDspTime + index * this.m_secondsPerBeat;
|
||||
if (index == 0)
|
||||
{
|
||||
Debug.Log($"[BeatClock] BeatCoroutine waiting, nextTime={nextTime}, now={AudioSettings.dspTime}");
|
||||
}
|
||||
yield return new WaitUntil(() => AudioSettings.dspTime >= nextTime - 0.02);
|
||||
|
||||
while (AudioSettings.dspTime < nextTime)
|
||||
yield return null;
|
||||
|
||||
if (this.m_blendError || this.m_stopped){
|
||||
Debug.Log($"[BeatClock] Coroutine exiting early, blendError={m_blendError}, stopped={m_stopped}");
|
||||
yield break;
|
||||
}
|
||||
this.m_onBeat?.Invoke(this.m_containerId);
|
||||
Debug.Log($"[Beat] index={index}, nextTime={nextTime:F4}, actualDspTime={AudioSettings.dspTime:F4}, diff={(AudioSettings.dspTime - nextTime)*1000:F1}ms");
|
||||
index++;
|
||||
}
|
||||
}
|
||||
@@ -99,7 +93,6 @@ namespace OCES.Audio
|
||||
while (AudioSettings.dspTime < nextTime)
|
||||
yield return null;
|
||||
if (this.m_blendError || this.m_stopped){
|
||||
Debug.Log($"[BeatClock] Coroutine exiting early, blendError={m_blendError}, stopped={m_stopped}");
|
||||
yield break;
|
||||
}
|
||||
this.m_onBar?.Invoke(this.m_containerId);
|
||||
@@ -118,7 +111,6 @@ namespace OCES.Audio
|
||||
while (AudioSettings.dspTime < nextTime)
|
||||
yield return null;
|
||||
if (this.m_blendError || this.m_stopped){
|
||||
Debug.Log($"[BeatClock] Coroutine exiting early, blendError={m_blendError}, stopped={m_stopped}");
|
||||
yield break;
|
||||
}
|
||||
this.m_onGrid?.Invoke(this.m_containerId);
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace OCES.Audio
|
||||
Action onFinished)
|
||||
{
|
||||
float effectiveBpm = container.Bpm > 0f ? container.Bpm : inheritedBpm;
|
||||
Debug.Log($"[MusicContainerPlayer] OnContainerEntered firing, container={container.Id}, subscribers={OnContainerEntered != null}");
|
||||
//Debug.Log($"[MusicContainerPlayer] OnContainerEntered firing, container={container.Id}, subscribers={OnContainerEntered != null}");
|
||||
OnContainerEntered?.Invoke(container, effectiveBpm, AudioSettings.dspTime);
|
||||
|
||||
int loopsCompleted = 0;
|
||||
|
||||
Reference in New Issue
Block a user