这个脚本是用来下载assetbuild的 unity2017.3的UnityWebRequest新增了DownloadHandlerFile的支持函数,可以直接将文件下载到外存(可以少写很多代码),也用来把StreamingAssets里的文件复制到persistentDataPath(在移动端C#的IO库好像读不了StreamingAssets里的文件)
*unity2017.2的UnityWebRequest新增timeout属性,用来设置超时时间(又可以少写很多代码)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using System;
using System.IO;
public class ABDownLoad : MonoBehaviour
{
float m_downCount=0;
public void Download(string _newFileIP, string _newFilesPath,string _oldFilesPath,Action<float> _peogress)
{
StartCoroutine (download(_newFileIP,_newFilesPath,_oldFilesPath,_peogress));
}
IEnumerator download(string _newFileIP, string _newFilesPath,string _oldFilesPath,Action<float> _peogress)
{
string newFilesJson;
string loadNewFileUrl = _newFileIP + "/" + _newFilesPath;
if(loadNewFileUrl.IndexOf("file:///")==-1 && loadNewFileUrl.IndexOf("http")!=0)
{
loadNewF

本文介绍如何使用Unity 2017.3的新特性UnityWebRequest的DownloadHandlerFile功能,简洁地实现将assetbundle文件下载到外部存储,并讨论如何将StreamingAssets中的文件复制到persistentDataPath,因为移动设备的C# IO库无法直接读取StreamingAssets内容。同时提到了UnityWebRequest在2017.2版本增加的timeout属性,用于设置下载超时时间。
最低0.47元/天 解锁文章
2415





