继续重构调整(UI)
- 引入 UniTask 和异步版本的 UIModule - 调整 Runtime/UIBase 和 Presentation 下的脚本命名空间到 SepCore.UI - 将原来的 5 层 UI 迁移到异步实现 - 规范各层的 UI 脚本命名
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using GameFramework;
|
||||
using GameFramework.Sound;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace UnityGameFramework.Runtime.AsyncTask
|
||||
{
|
||||
/// <summary>
|
||||
/// Sound 异步扩展方法
|
||||
/// </summary>
|
||||
public static class SoundAsyncExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步播放声音
|
||||
/// </summary>
|
||||
/// <param name="soundComponent">声音组件</param>
|
||||
/// <param name="soundAssetName">声音资源名称</param>
|
||||
/// <param name="soundGroupName">声音组名称</param>
|
||||
/// <param name="playSoundParams">播放声音参数</param>
|
||||
/// <param name="userData">用户自定义数据</param>
|
||||
/// <param name="timeout">超时时间(秒),0表示不超时</param>
|
||||
/// <returns>播放成功事件</returns>
|
||||
public static UniTask<PlaySoundSuccessEventArgs> PlaySoundAsync(this SoundComponent soundComponent,
|
||||
string soundAssetName,
|
||||
string soundGroupName,
|
||||
PlaySoundParams playSoundParams = null,
|
||||
object userData = null,
|
||||
float timeout = 30f)
|
||||
{
|
||||
int serialId = 0;
|
||||
UniTask<PlaySoundSuccessEventArgs> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<PlaySoundSuccessEventArgs, PlaySoundFailureEventArgs>(
|
||||
PlaySoundSuccessEventArgs.EventId,
|
||||
PlaySoundFailureEventArgs.EventId,
|
||||
successArgs => successArgs.SerialId == serialId,
|
||||
failureArgs => failureArgs.SerialId == serialId,
|
||||
timeout
|
||||
);
|
||||
|
||||
serialId = soundComponent.PlaySound(soundAssetName, soundGroupName, 0, playSoundParams, userData);
|
||||
return waitTask;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user