記錄一個問題:
游戲內播放完音頻A再去循環播放音頻B,在協程里使用等待n秒來實現拼接,發現在個別手機上會有卡頓的問題,盲猜是和幀率有關。
這是最初的實現方案:
IEnumerator IEPlayAudio(){if(ASOnBeginDrag != null){AudioClip clip = ASOnBeginDrag.clip;if(clip != null){float m_AudioLen = clip.length;ASOnBeginDrag.Play();yield return new WaitForSeconds(m_AudioLen);if (ASOnDrag != null){ASOnDrag.Play();ASOnDrag.loop = true;}}}yield return null;}
這是修改后的代碼:
void PlayBeginDragAudio(){if(ASOnBeginDrag != null){ASOnBeginDrag.Play();if (ASOnDrag != null){//使用Audio System絕對時間來處理音頻拼接問題ASOnDrag.PlayScheduled(AudioSettings.dspTime + m_AudioLen);ASOnDrag.loop = true;}}}
AudioSourec.PlayScheduled(AudioSettings.dspTime + timeInterval);
表示在當前Audio System絕對時間之后的timeInterval秒,來播放;同時想要停止這個操作只需要AudioSourec.Stop()即可。