示例#1
0
        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 Helpers.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 Helpers.WebRequestException(www.error));
         }
     }
     catch (Exception e)
     {
         tcs.TrySetException(e);
     }
 }