We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我正在使用 AudioKit 中的
public static AudioPlayer PlaySound(AudioClip clip, bool loop = false, Action<AudioPlayer> callBack = null, float volume = 1.0f)
播放某个 UI 音效,此时游戏时暂停的(Time.timeScale = 0),传入的 callback 事件在音效播放完毕后未执行,而是在游戏恢复时才一起执行。
Time.timeScale = 0
QF version: 1.0141
The text was updated successfully, but these errors were encountered:
我了解到 Unity 原生的 AudioSource 没有提供结束事件接口,网上大致通过两种协程方式判断:1)等待 AudioChip.length 时间长度;2)根据 AudioSource.IsPlaying 状态判断。我目前采用第二种方法,并封装了一个自己的 AudioSource:
AudioChip.length
AudioSource.IsPlaying
public void Pause() { _isPaused = true; _audioSource?.Pause(); } public void Resume() { _audioSource?.UnPause(); _isPaused = false; } public void Stop() { _audioSource?.Stop(); } private IEnumerator FinishCoroutine(Action<MyAudioSource> onFinish) { yield return new WaitUntil(() => !_audioSource.isPlaying && !_isPaused); onFinish?.Invoke(this); }
上述逻辑对我是有效的,它不会受到 Time.timeScale 的影响(因为音频的播放也不会受到该影响,所以我认为这样是更合理的),当 AudioSource 正常播放完毕或者被 Stop 则会调用 onFinish,此外上述逻辑同样适用于 loop=true 的 AudioSource,而使用等待时间来监听是否完成处理 loop 的音频需要额外的逻辑处理。
Time.timeScale
onFinish
loop=true
Sorry, something went wrong.
No branches or pull requests
我正在使用 AudioKit 中的
播放某个 UI 音效,此时游戏时暂停的(
Time.timeScale = 0
),传入的 callback 事件在音效播放完毕后未执行,而是在游戏恢复时才一起执行。QF version: 1.0141
The text was updated successfully, but these errors were encountered: