/// <summary>Tracks and logs a request upon it completing.</summary> public static void DebugWebRequest(UnityWebRequestAsyncOperation operation, LocalUser userData, int timeSent = -1) { #if DEBUG DebugUtilities.DebugDownload(operation, userData, null, timeSent); #endif // DEBUG }
private static void DownloadModBinary_Internal(ModfileIdPair idPair, string downloadURL) { FileDownloadInfo downloadInfo = modfileDownloadMap[idPair]; downloadInfo.request = UnityWebRequest.Get(downloadURL); string tempFilePath = downloadInfo.target + ".download"; DataStorage.WriteFile(tempFilePath, new byte[0], (p, success) => { if (success) { downloadInfo.request.downloadHandler = new DownloadHandlerFile(tempFilePath); #if PLATFORM_PS4 // NOTE(@jackson): This workaround addresses an issue in UnityWebRequests on the // PS4 whereby redirects fail in specific cases. Special thanks to @Eamon of // Spiderling Studios (http://spiderlinggames.co.uk/) downloadInfo.request.redirectLimit = 0; #endif var operation = downloadInfo.request.SendWebRequest(); #if DEBUG DebugUtilities.DebugDownload(operation, LocalUser.instance, tempFilePath); #endif operation.completed += (o) => DownloadClient.OnModBinaryRequestCompleted(idPair); DownloadClient.StartMonitoringSpeed(); // notify download started if (DownloadClient.modfileDownloadStarted != null) { DownloadClient.modfileDownloadStarted(idPair, downloadInfo); } } else if (DownloadClient.modfileDownloadFailed != null) { string warningInfo = ("Failed to create download file on disk." + "\nSource: " + downloadURL + "\nDestination: " + tempFilePath + "\n\n"); modfileDownloadFailed(idPair, WebRequestError.GenerateLocal(warningInfo)); } }); }
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); }