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:
@@ -12,9 +12,9 @@ namespace OCES.Audio
|
||||
internal class SyncPointState
|
||||
{
|
||||
public SyncPoint Mode;
|
||||
public int BaseTimeSamples; // 读取旧 Source 时的 timeSamples
|
||||
public double BaseDspTime; // 读取旧 Source 时的 dspTime
|
||||
public int SampleRate; // 旧 Source 的采样率
|
||||
public int BaseTimeSamples; // 读取Source Segment 的 timeSamples
|
||||
public double BaseDspTime; // 读取Source Segment 的 dspTime
|
||||
public int SampleRate; // Source Segment 的采样率
|
||||
public bool Ready;
|
||||
}
|
||||
|
||||
@@ -107,9 +107,9 @@ namespace OCES.Audio
|
||||
if (syncState is { Mode: SyncPoint.SameAsCurrentSegment })
|
||||
{
|
||||
AudioSource newSource = CurrentHandle?.GetFirstLeafSource();
|
||||
if (newSource != null && newSource.clip != null)
|
||||
if (newSource && newSource.clip)
|
||||
{
|
||||
// 计算从读取旧 Source 到现在经过的 samples
|
||||
// 计算从读取Source Segment 到现在经过的 samples
|
||||
double elapsedSeconds = AudioSettings.dspTime - syncState.BaseDspTime;
|
||||
int elapsedSamples = (int)(elapsedSeconds * syncState.SampleRate);
|
||||
int targetTimeSamples = syncState.BaseTimeSamples + elapsedSamples;
|
||||
|
||||
Reference in New Issue
Block a user