UnityWebRequest使用await

需要扩展一下UnityWebRequestAsyncOperation

using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using UnityEngine.Networking;

public static class ExtensionMethods
{
    public static TaskAwaiter<object> GetAwaiter(this UnityWebRequestAsyncOperation op)
    {
        var tcs = new TaskCompletionSource<object>();
        op.completed += (obj) =>
        {
            tcs.SetResult(null);
        };
        return tcs.Task.GetAwaiter();
    }
}



首页 我的博客
粤ICP备17103704号