The DownloadAsync
method in the Editor.EditorUtility
class is a static method used to asynchronously download a file from a specified URL and save it to a target file path. It provides progress updates and supports cancellation.
The DownloadAsync
method in the Editor.EditorUtility
class is a static method used to asynchronously download a file from a specified URL and save it to a target file path. It provides progress updates and supports cancellation.
To use the DownloadAsync
method, provide the URL of the file to download, the target file path where the file should be saved, a callback for progress updates, and a cancellation token to support task cancellation.
The method returns a Task<bool>
that completes with true
if the download is successful, or false
if it fails.
// Example usage of DownloadAsync string url = "https://example.com/file.zip"; string targetFile = "C:\Downloads\file.zip"; var progressCallback = new Sandbox.Utility.DataProgress.Callback((progress) => { // Handle progress updates Console.WriteLine($"Download progress: {progress * 100}%"); }); var cancellationToken = new System.Threading.CancellationToken(); var downloadTask = Editor.EditorUtility.DownloadAsync(url, targetFile, progressCallback, cancellationToken); // Await the task to ensure completion bool success = await downloadTask; if (success) { // Handle successful download Console.WriteLine("Download completed successfully."); } else { // Handle download failure Console.WriteLine("Download failed."); }