Version: 2017.3
public bool removeFileOnAbort ;

描述

如果下载被中止(手动中止或因出现错误而中止),则应删除创建的文件。默认值:false。

using System.Collections;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;

public class DownloadHandlerFileSample : MonoBehaviour { void Start() { StartCoroutine(Download()); }

IEnumerator Download() { var uwr = new UnityWebRequest("http://unity3d.com/"); uwr.method = UnityWebRequest.kHttpVerbGET; var resultFile = Path.Combine(Application.persistentDataPath, "result.txt"); var dh = new DownloadHandlerFile(resultFile); dh.removeFileOnAbort = true; uwr.downloadHandler = dh; yield return uwr.Send(); if (uwr.isNetworkError || uwr.isHttpError) Debug.Log(uwr.error); else { Debug.Log("Download saved to: " + resultFile); } } }