Пример #1
0
        public static ImageRequest DownloadModGalleryImage(ModProfile profile,
                                                           string imageFileName,
                                                           ModGalleryImageSize size)
        {
            ImageRequest request = new ImageRequest();

            string imageURL = profile.media.GetGalleryImageWithFileName(imageFileName).GetSizeURL(size);

            UnityWebRequest webRequest = UnityWebRequest.Get(imageURL);

            webRequest.downloadHandler = new DownloadHandlerTexture(true);

            var operation = webRequest.SendWebRequest();

            operation.completed += (o) => DownloadClient.OnImageDownloadCompleted(operation, request);

            return(request);
        }
Пример #2
0
        private static void OnImageDownloadCompleted(UnityWebRequestAsyncOperation operation,
                                                     ImageRequest request)
        {
            UnityWebRequest webRequest = operation.webRequest;

            request.isDone = true;

            if (webRequest.isNetworkError || webRequest.isHttpError)
            {
                request.error = WebRequestError.GenerateFromWebRequest(webRequest);
                request.NotifyFailed();
            }
            else
            {
                request.imageTexture = (webRequest.downloadHandler as DownloadHandlerTexture).texture;
                request.NotifySucceeded();
            }
        }
Пример #3
0
        // ---------[ IMAGE DOWNLOADS ]---------
        public static ImageRequest DownloadModLogo(ModProfile profile, LogoSize size)
        {
            ImageRequest request = new ImageRequest();

            request.isDone = false;

            string logoURL = profile.logoLocator.GetSizeURL(size);

            UnityWebRequest webRequest = UnityWebRequest.Get(logoURL);

            webRequest.downloadHandler = new DownloadHandlerTexture(true);

            var operation = webRequest.SendWebRequest();

            operation.completed += (o) => DownloadClient.OnImageDownloadCompleted(operation, request);

            return(request);
        }
Пример #4
0
        public static ImageRequest DownloadUserAvatar(UserProfile profile,
                                                      UserAvatarSize size)
        {
            Debug.Assert(profile != null, "[mod.io] Profile parameter cannot be null");

            ImageRequest request = null;

            if (profile.avatarLocator == null ||
                String.IsNullOrEmpty(profile.avatarLocator.GetSizeURL(size)))
            {
                Debug.LogWarning("[mod.io] User Profile has no associated avatar information");
            }
            else
            {
                request = DownloadImage(profile.avatarLocator.GetSizeURL(size));
            }

            return(request);
        }
Пример #5
0
        public static ImageRequest DownloadImage(string imageURL)
        {
            ImageRequest request = new ImageRequest();

            request.isDone = false;

            UnityWebRequest webRequest = UnityWebRequest.Get(imageURL);

            webRequest.downloadHandler = new DownloadHandlerTexture(true);

            var operation = webRequest.SendWebRequest();

            operation.completed += (o) => DownloadClient.OnImageDownloadCompleted(operation, request);


            #if DEBUG
            if (PluginSettings.data.logAllRequests)
            {
                string        requestHeaders = "";
                List <string> requestKeys    = new List <string>(APIClient.UNITY_REQUEST_HEADER_KEYS);
                requestKeys.AddRange(APIClient.MODIO_REQUEST_HEADER_KEYS);

                foreach (string headerKey in requestKeys)
                {
                    string headerValue = webRequest.GetRequestHeader(headerKey);
                    if (headerValue != null)
                    {
                        requestHeaders += "\n" + headerKey + ": " + headerValue;
                    }
                }

                int timeStamp = ServerTimeStamp.Now;
                Debug.Log("IMAGE REQUEST SENT"
                          + "\nTimeStamp: [" + timeStamp.ToString() + "] "
                          + ServerTimeStamp.ToLocalDateTime(timeStamp).ToString()
                          + "\nURL: " + webRequest.url
                          + "\nHeaders: " + requestHeaders);
            }
            #endif

            return(request);
        }
Пример #6
0
        public static ImageRequest DownloadImage(string imageURL)
        {
            ImageRequest request = new ImageRequest();

            request.isDone = false;

            UnityWebRequest webRequest = UnityWebRequest.Get(imageURL);

            webRequest.downloadHandler = new DownloadHandlerTexture(true);

            var operation = webRequest.SendWebRequest();

            operation.completed += (o) => DownloadClient.OnImageDownloadCompleted(operation, request);


            #if DEBUG
            DebugUtilities.DebugDownload(operation, LocalUser.instance, null);
            #endif

            return(request);
        }
Пример #7
0
        public static ImageRequest DownloadImage(string imageURL)
        {
            ImageRequest request = new ImageRequest();

            request.isDone = false;

            UnityWebRequest webRequest = UnityWebRequest.Get(imageURL);

            webRequest.downloadHandler = new DownloadHandlerTexture(true);

            #if DEBUG
            if (DownloadClient.logAllRequests)
            {
                string        requestHeaders = "";
                List <string> requestKeys    = new List <string>(APIClient.UNITY_REQUEST_HEADER_KEYS);
                requestKeys.AddRange(APIClient.MODIO_REQUEST_HEADER_KEYS);

                foreach (string headerKey in requestKeys)
                {
                    string headerValue = webRequest.GetRequestHeader(headerKey);
                    if (headerValue != null)
                    {
                        requestHeaders += "\n" + headerKey + ": " + headerValue;
                    }
                }

                Debug.Log("GENERATING DOWNLOAD REQUEST"
                          + "\nURL: " + webRequest.url
                          + "\nHeaders: " + requestHeaders
                          + "\n"
                          );
            }
            #endif

            var operation = webRequest.SendWebRequest();
            operation.completed += (o) => DownloadClient.OnImageDownloadCompleted(operation, request);

            return(request);
        }