unity 文件下载到外存

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个脚本是用来下载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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值