此处需要手动开启协程
未考虑网络文件变动的问题,需要的话可以自行进行md5比对
若需要分片下载,可以通过修改Range相关值实现
using System;
using System.Collections;
using System.IO;
using UnityEngine.Networking;
public class HttpDownLoad
{
public float progress { get; private set; }
public bool isDone { get; private set; }
private bool isStop;
public IEnumerator Start(string url, string filePath, Action callBack)
{
var headRequest = UnityWebRequest.Head(url);
yield return headRequest.SendWebRequest();
var totalLength = long.Parse(headRequest.GetResponseHeader("Content-Length"));
var dirPath = Path.GetDirectoryName(filePath);
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
}
using (var fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write))
{
var fileLength = fs.Length;
if (fileLeng