UnityWebRequest下载文件

2020-03-18 18:02:48 浏览数 (1)

获取文件信息

代码语言:javascript复制
UnityWebRequest header = UnityWebRequest.Head(o.previewUrl);
yield return header.SendWebRequest();
if (!header.isHttpError && !header.isNetworkError)
{
    flLength = long.Parse(header.GetResponseHeader("Content-Length"));
}

下载请求

代码语言:javascript复制
UnityWebRequest request = UnityWebRequest.Get(o.previewUrl);
yield return request.SendWebRequest();
if (!request.isHttpError && !request.isNetworkError)
{}

显示进度条

update中更新进度条

代码语言:javascript复制
//进度条
if (panelProgress != null&& requestDwn!=null&&flCount > 0&& flLength>0)
{
    float progress = (float)requestDwn.downloadedBytes / flLength * (1f / flCount);
    //Debug.Log(progress   "---"   lastProgress);
    if(requestDwn.downloadedBytes == flLength)
        progress = Mathf.Ceil(lastProgress / (1f / flCount)) * (1f / flCount);
    else
        progress  = Mathf.Floor(lastProgress / (1f /

0 人点赞