예제 #1
0
        public static T GetResult <T>(this UnityWebRequest self, IJsonReader r)
        {
            AssertV2.IsTrue(self.isDone, "web request was not done!");
            if (TypeCheck.AreEqual <T, UnityWebRequest>())
            {
                return((T)(object)self);
            }
            if (typeof(Texture2D).IsCastableTo(typeof(T)))
            {
                AssertV2.IsTrue(self.downloadHandler is DownloadHandlerTexture, "self.downloadHandler was not a DownloadHandlerTexture");
                var h = (DownloadHandlerTexture)self.downloadHandler;
                return((T)(object)h.texture);
            }
            if (TypeCheck.AreEqual <T, Stream>())
            {
                return((T)(object)new MemoryStream(self.downloadHandler.data));
            }
            if (TypeCheck.AreEqual <T, byte[]>())
            {
                return((T)(object)self.downloadHandler.data);
            }
            if (TypeCheck.AreEqual <T, Headers>())
            {
                return((T)(object)self.GetResponseHeadersV2());
            }
            var text = self.downloadHandler.text;

            if (TypeCheck.AreEqual <T, string>())
            {
                return((T)(object)text);
            }
            return(r.Read <T>(text));
        }
예제 #2
0
        public async Task <Headers> GetResultHeaders()
        {
            if (request.isModifiable)
            {
                return(await GetResult <Headers>());
            }
            await WaitForRequestToFinish();

            return(request.GetResponseHeadersV2());
        }
예제 #3
0
 public async Task <Headers> GetResultHeaders()
 {
     if (request.isModifiable)
     {
         return(await GetResult <Headers>());
     }
     while (!request.isDone && !request.isHttpError && !request.isNetworkError)
     {
         await TaskV2.Delay(5);
     }
     return(request.GetResponseHeadersV2());
 }
예제 #4
0
 public Task <Headers> GetResultHeaders()
 {
     return(MainThread.instance.ExecuteOnMainThreadAsync(async() => {
         waitForRequestToBeConfigured.TrySetResult(true);
         if (request.isModifiable)
         {
             return await GetResult <Headers>();
         }
         await WaitForRequestToFinish();
         return request.GetResponseHeadersV2();
     }));
 }
예제 #5
0
 public async Task <Headers> GetResultHeaders()
 {
     if (request.isModifiable)
     {
         throw new Exception("Request was not send yet, can't get result headers");
     }
     while (!request.isDone && !request.isHttpError && !request.isNetworkError)
     {
         await TaskV2.Delay(5);
     }
     return(request.GetResponseHeadersV2());
 }
예제 #6
0
        public static T GetResult <T>(this UnityWebRequest self, IJsonReader r)
        {
            AssertV2.IsTrue(self.isDone, "web request was not done!");
            if (TypeCheck.AreEqual <T, UnityWebRequest>())
            {
                return((T)(object)self);
            }
            if (typeof(Texture2D).IsCastableTo(typeof(T)))
            {
                AssertV2.IsTrue(self.downloadHandler is DownloadHandlerTexture,
                                "self.downloadHandler was not a DownloadHandlerTexture but a " + self.downloadHandler.GetType());
                var h = (DownloadHandlerTexture)self.downloadHandler;
                return((T)(object)h.texture);
                //return (T)(object)DownloadHandlerTexture.GetContent(self);
            }
            if (typeof(T).IsCastableTo <Exception>() && self.GetStatusCode().IsErrorStatus())
            {
                return((T)(object)new NoSuccessError(self.GetStatusCode(), self.GetResult <string>()));
            }
            if (TypeCheck.AreEqual <T, HttpStatusCode>())
            {
                return((T)(object)self.GetStatusCode());
            }
            if (TypeCheck.AreEqual <T, Stream>())
            {
                return((T)(object)new MemoryStream(GetBytesResult(self)));
            }
            if (TypeCheck.AreEqual <T, byte[]>())
            {
                return((T)(object)GetBytesResult(self));
            }
            if (TypeCheck.AreEqual <T, Headers>())
            {
                return((T)(object)self.GetResponseHeadersV2());
            }
            var text = GetStringResult(self);

            if (TypeCheck.AreEqual <T, string>())
            {
                return((T)(object)text);
            }
            return(r.Read <T>(text));
        }