示例#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 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));
        }