同事让我写个工具类, 先记录,还没证实,用的时候再说
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class DownHelper : MonoBehaviour
{
private string cc = @"https://www.baidu.com/img/bd_logo1.png";
private string LoadPro;
public void Update()
{
play1(cc);
}
public void DownFiles(string FormPath)
{
byte[] bytes = new byte[1024]; //
StartCoroutine(DownFile(FormPath, bytes));
}
private IEnumerator DownFile(string url, byte[] bytes)
{
WWW www = new WWW(url);
LoadPro = (((int)(www.progress * 100)) % 100) + "%"; //下载百分数
yield return www;
if (www.error != null)
{
Debug.Log(www.error);
yield break;
}
if (www.isDone)
{
//float a = www.progress;
Debug.Log(LoadPro); //进度
Debug.Log("下载完成");
Debug.Log("文件大小" + www.bytes.Length);
bytes = www.bytes;
Debug.Log(bytes);//字节
}
else
{
LoadPro = "100%";
}
}
}