标签:www DownloadMgr 路径 下载 CurrDownloadData progress 资源
DownloadMgr 普通类单例
AssetBundleDownload 继承mono单例
AssetBundleDownloadRoutine 继承mono的脚本
DownloadDataEntity 自定义数据实体
资源下载流程:
1.检查持久化路径下是否有版本文件,如果有检查资源更新,如果没有检查streaming路径是否有版本文件,如果没有检查资源更新,如果有将streaming路径下文件解压到持久化路径
public class DownloadDataEntity
{
public string FullName;
public string MD5;
public int Size;
public bool IsFirstData;
}
private IEnumerator DownloadData()
{
if (NeedDownloadCount == 0) yield break;
m_CurrDownloadData = m_List[0];//当前正在下载的实体
//服务器上的资源下载路径
string dataUrl = DownloadMgr.DownloadUrl + m_CurrDownloadData.FullName;
int index = m_CurrDownloadData.FullName.LastIndexOf('\\');
string shortPath = m_CurrDownloadData.FullName.Substring(0, index);//短路径 用于创建文件夹
string localFolderPath = Application.persistentDataPath + "/" + shortPath;//得到本地路径 即在客户端本地当前下载文件存放的文件夹路径
if (!Directory.Exists(localFolderPath))
{
Directory.CreateDirectory(localFolderPath);
}
WWW www = new WWW(dataUrl);
float timeout = Time.time;
float progress = www.progress;
while (www != null && www.isDone == false)
{
if (progress < www.progress)
{
timeout = Time.time;
progress = www.progress;
m_CurrDownloadSize = (int)(m_CurrDownloadData.Size * progress);//当前正在下载的文件 已经下载好的大小
}
if ((Time.time - timeout) > DownloadMgr.DownloadTimeOut)
{
AppDebug.LogError("download fail!");
yield break;
}
yield return null;//一定要等一帧 否则会卡死
}
yield return www;
if (www != null && www.error == null)
{
using (FileStream fs = new FileStream(DownloadMgr.Instance.LocalFilePath + m_CurrDownloadData.FullName, FileMode.Create, FileAccess.ReadWrite))
{
fs.Write(www.bytes, 0, www.bytes.Length);
}
}
//下载成功
m_CurrDownloadSize = 0;//当前正在下载的文件已经下载完毕 此刻没有正在下载的文件
m_DownloadSize += m_CurrDownloadData.Size;//总下载文件大小 加上刚刚下载完毕的文件大小
//写入本地版本文件
DownloadMgr.Instance.ModifyLocalData(m_CurrDownloadData);
m_List.RemoveAt(0);//将已经下载完成的对象从需要下载列表移除
CompletedCount++;//已经下载完成的数量加一
if (m_List.Count == 0)//需要下载列表为空
{
m_List.Clear();
}
else//需要下载列表不为空 继续下载
{
IsStartDownload = true;
}
}
标签:www,DownloadMgr,路径,下载,CurrDownloadData,progress,资源 来源: https://blog.csdn.net/qq_40742335/article/details/113182000
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。