using System; using Cysharp.Threading.Tasks; using GameFramework; using GameFramework.Sound; using UnityGameFramework.Runtime; namespace UnityGameFramework.Runtime.AsyncTask { /// /// Sound 异步扩展方法 /// public static class SoundAsyncExtension { /// /// 异步播放声音 /// /// 声音组件 /// 声音资源名称 /// 声音组名称 /// 播放声音参数 /// 用户自定义数据 /// 超时时间(秒),0表示不超时 /// 播放成功事件 public static UniTask PlaySoundAsync(this SoundComponent soundComponent, string soundAssetName, string soundGroupName, PlaySoundParams playSoundParams = null, object userData = null, float timeout = 30f) { int serialId = 0; UniTask waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync( PlaySoundSuccessEventArgs.EventId, PlaySoundFailureEventArgs.EventId, successArgs => successArgs.SerialId == serialId, failureArgs => failureArgs.SerialId == serialId, timeout ); serialId = soundComponent.PlaySound(soundAssetName, soundGroupName, 0, playSoundParams, userData); return waitTask; } } }