您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

39 行
1.3 KiB

using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using UnityEngine.Networking;
namespace Unity.Services.Lobbies.Http
{
public static class UnityWebRequestHelpers
{
public static TaskAwaiter<HttpClientResponse> GetAwaiter(this UnityWebRequestAsyncOperation asyncOp)
{
var tcs = new TaskCompletionSource<HttpClientResponse>();
asyncOp.completed += obj =>
{
var result = CreateHttpClientResponse((UnityWebRequestAsyncOperation) obj);
tcs.SetResult(result);
};
return tcs.Task.GetAwaiter();
}
internal static HttpClientResponse CreateHttpClientResponse(UnityWebRequestAsyncOperation unityResponse)
{
var response = unityResponse.webRequest;
var result = new HttpClientResponse(
response.GetResponseHeaders(),
response.responseCode,
#if UNITY_2020_1_OR_NEWER
response.result == UnityWebRequest.Result.ProtocolError,
response.result == UnityWebRequest.Result.ConnectionError,
#else
response.isHttpError,
response.isNetworkError,
#endif
response.downloadHandler.data,
response.error);
return result;
}
}
}