private static void OnTaskCompleted <T>(TaskCompletionSource <T> tcs, UnityWebRequest request) where T : class
        {
            try
            {
#if UNITY_5
                if (request.isError)
#else
                if (request.isHttpError || request.isNetworkError)
#endif
                {
                    tcs.TrySetException(new WebRequestException(request.error, request.responseCode));
                }
                else if (request.downloadHandler != null)
                {
                    var result = AsyncWww.GetResult <T>(request);
                    tcs.TrySetResult(result);
                }
                else
                {
                    tcs.TrySetResult(null);
                }
            }
            catch (Exception e)
            {
                tcs.TrySetException(e);
            }
        }
示例#2
0
 private static void OnTaskCompleted <T>(TaskCompletionSource <T> tcs, WWW www) where T : class
 {
     try
     {
         if (string.IsNullOrEmpty(www.error))
         {
             var result = AsyncWww.GetResult <T>(www);
             tcs.TrySetResult(result);
         }
         else
         {
             tcs.TrySetException(new WebRequestException(www.error));
         }
     }
     catch (Exception e)
     {
         tcs.TrySetException(e);
     }
 }
示例#3
0
 /// <summary>
 /// Initializes the operation result value. Called when the underlying <see cref="UnityWebRequest"/> has completed withou errors.
 /// </summary>
 protected virtual T GetResult(UnityWebRequest request)
 {
     return(AsyncWww.GetResult <T>(request));
 }
示例#4
0
 /// <summary>
 /// Initializes the operation result value. Called when the underlying <see cref="WWW"/> has completed withou errors.
 /// </summary>
 protected virtual T GetResult(WWW request)
 {
     return(AsyncWww.GetResult <T>(request));
 }