我的Unity学习笔记之——Unity中从网站下载ab资源+下载存储一条龙
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using System.IO; public class DownLoadAssetBundle : MonoBehaviour { private string mainAssetBundleURL = @"http://www.XXX.com/AssetBundles/AssetBundles"; private string allAssetBundleURL = @"http://www.XXX.com/AssetBundles/"; void Start () { StartCoroutine("DownLoadMainAssetBundel"); } IEnumerator DownLoadMainAssetBundel()
{
UnityWebRequest request = UnityWebRequest.GetAssetBundle(mainAssetBundleURL);
yield return request.Send();
AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request);
//Debug.Log("OK");
AssetBundleManifest manifest = ab.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
string[] names = manifest.GetAllAssetBundles();
for (int i = ; i < names.Length; i++)
{
Debug.Log(allAssetBundleURL + names[i]);
StartCoroutine(DownLoadSingleAssetBundel(allAssetBundleURL + names[i]));
}
}
/// <summary>
/// 下载单个AB文件
/// </summary>
IEnumerator DownLoadSingleAssetBundel(string url)
{
UnityWebRequest request = UnityWebRequest.GetAssetBundle(url);
yield return request.Send();
AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request);
//Debug.Log("OK"); string[] names = ab.GetAllAssetNames();
for (int i = ; i < names.Length; i++)
{ string tempName = Path.GetFileNameWithoutExtension(names[i]);
//Debug.Log(tempName); GameObject gameObject = ab.LoadAsset<GameObject>(tempName);
GameObject.Instantiate<GameObject>(gameObject); } } }
下面是下载存储一条龙
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using System.IO; public class DownLoadAssetBundle : MonoBehaviour { private string mainAssetBundleURL = @"http://www.XXX.com/AssetBundles/AssetBundles"; private string allAssetBundleURL = @"http://www.XXX.com/AssetBundles/"; void Start () { StartCoroutine("DownLoadMainAssetBundel"); } IEnumerator DownLoadMainAssetBundel()
{
UnityWebRequest request = UnityWebRequest.GetAssetBundle(mainAssetBundleURL);
yield return request.Send();
AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request);
//Debug.Log("OK");
AssetBundleManifest manifest = ab.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
string[] names = manifest.GetAllAssetBundles();
for (int i = ; i < names.Length; i++)
{
Debug.Log(allAssetBundleURL + names[i]);
//StartCoroutine(DownLoadSingleAssetBundel(allAssetBundleURL + names[i]));
StartCoroutine(DownLoadAssetBundelAbdSave(allAssetBundleURL + names[i]));
}
}
/// <summary>
/// 下载单个AB文件不保存
/// </summary>
IEnumerator DownLoadSingleAssetBundel(string url)
{
UnityWebRequest request = UnityWebRequest.GetAssetBundle(url);
yield return request.Send();
AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request);
//Debug.Log("OK"); string[] names = ab.GetAllAssetNames();
for (int i = ; i < names.Length; i++)
{ string tempName = Path.GetFileNameWithoutExtension(names[i]);
//Debug.Log(tempName); GameObject gameObject = ab.LoadAsset<GameObject>(tempName);
GameObject.Instantiate<GameObject>(gameObject); } }
/// <summary>
/// 下载AB文件并保存到本地
/// </summary>
/// <returns></returns>
IEnumerator DownLoadAssetBundelAbdSave(string url)
{
WWW www = new WWW(url);
yield return www;
if(www.isDone)
{
//表示资源下载完毕使用IO技术把www对象存储到本地
SaveAssetBundle(Path.GetFileName(url), www.bytes, www.bytes.Length); }
}
/// <summary>
/// 存储AB文件到本地
/// </summary>
private void SaveAssetBundle(string fileName, byte[] bytes, int count)
{
FileInfo fileInfo = new FileInfo(Application.streamingAssetsPath + "//" + fileName);
FileStream fs = fileInfo.Create();
fs.Write(bytes, , count);
fs.Flush();
fs.Close();
fs.Dispose();
Debug.Log(fileName + "下载并存储完成");
} }
我的Unity学习笔记之——Unity中从网站下载ab资源+下载存储一条龙的更多相关文章
- Unity学习笔记(4) --- Unity的界面排版:初识GUI
GUI和GUILayout是Unity提供的UIKit.在使用GUI的Controls时都要求设置Rect參数.没办法做到自己主动排版,给适配带来难度.而GUILayout的设计就是为了弥补这个缺陷, ...
- 并发编程学习笔记(4)----jdk5中提供的原子类及Lock使用及原理
(1)jdk中原子类的使用: jdk5中提供了很多原子类,它会使变量的操作变成原子性的. 原子性:原子性指的是一个操作是不可中断的,即使是在多个线程一起操作的情况下,一个操作一旦开始,就不会被其他线程 ...
- [学习笔记] 在Eclipse中导入项目
参考前文:[学习笔记] 在Eclips 中导出项目 选择已经导出的文件: 导入之后,项目结构如下: 至此,完成.
- CockroachDB学习笔记——[译]CockroachDB中的SQL:映射表中数据到键值存储
CockroachDB学习笔记--[译]CockroachDB中的SQL:映射表中数据到键值存储 原文标题:SQL in CockroachDB: Mapping Table Data to Key- ...
- [学习笔记] 在Eclipse中导出可以直接运行的jar,依赖的jar中的类解压后放在运行jar中
前文: [学习笔记] 在Eclipse中导出可以直接运行的jar,依赖的jar打在jar包中 使用7z打开压缩包,查看所有依赖的jar都被解压以包名及class的方式存储在了运行jar中,此时jar的 ...
- [学习笔记] 在Eclipse中导出可以直接运行的jar,依赖的jar打在jar包中
本文需要参考前文: [学习笔记] 在Eclipse中导出可以直接运行的jar,依赖的jar在子目录中 上文是导出的运行的依赖jar被放在了子目录中,本文是将依赖jar放在可运行jar的本身,这样发布的 ...
- [学习笔记] 在Eclipse中导出可以直接运行的jar,依赖的jar在子目录中
工程创建可参考前文: [学习笔记] 在Eclipse中使用Hibernate,并创建第一个工程,数据库为Oracle XE 在工程上鼠标右键: 找到java 选择 Runable JAR file N ...
- Web安全学习笔记 SQL注入中
Web安全学习笔记 SQL注入中 繁枝插云欣 --ICML8 权限提升 数据库检测 绕过技巧 一.权限提升 1. UDF提权 UDF User Defined Function,用户自定义函数 是My ...
- (转) OpenCV学习笔记大集锦 与 图像视觉博客资源2之MIT斯坦福CMU
首页 视界智尚 算法技术 每日技术 来打我呀 注册 OpenCV学习笔记大集锦 整理了我所了解的有关OpenCV的学习笔记.原理分析.使用例程等相关的博文.排序不分先后,随机整理的 ...
随机推荐
- Linux系统下常用命令
yum [options] [command] [package ...] options:可选,选项包括-h(帮助),-y(当安装过程提示选择全部为"yes"),-q(不显示安装 ...
- PYTHON基础-入门
变量名可以是数字,字母,下划线,字母不能开头.
- ESP8266 01S WIFI 网络
ESP8266是一款超低功耗的UART-WiFi 透传模块,拥有业内极富竞争力的封装尺寸和超低能耗技术,专为移动设备和物联网应用设计,可将用户的物理设备连接到Wi-Fi 无线网络上,进行互联网或局域网 ...
- Linux - 文件和目录常用命令
文件和目录常用命令 目标 查看目录内容 ls 切换目录 cd 创建和删除操作 touch rm mkdir 拷贝和移动文件 cp mv 查看文件内容 cat more grep 其他 echo 重定向 ...
- Redux 检测状态树变更
一 概述 Redux只是检测引用是否改变. 如果状态树的某个值是对象.数组等,在reducer中需要生成一个新对象.新数组,才能被Redux检测到变更. let fruits = ['apple',' ...
- XML Linq 学习笔记
XML如下: <?xml version="1.0" encoding="utf-8"?> <Dishes> <Dish> ...
- windows server 2012 远程桌面不好使
下面的文章里讲的比较详细 http://www.hfkehu.cn/thread-4382-1-1.html 我遇到的问题是第一种,因为是刚装的机器,刚连上网时,选择如下设置时,因为鼠标一点别的地方, ...
- 十一、eclipse如何创建一个maven工程project
1. 2. 3. 4. 这是刚创建的工程,因为缺少WEB-INF/web.xml,所以项目会报错 5. 6. 再编写一个web.xml文件,项目就正常了,没有报错:后期需要自己添加对应的pom.xml ...
- idea配置git,查看git代码&拉取git项目至本地
1.点击file,右键选择setting 选择本地git安装路径 Ps:从git上导入一个全新的maven项目 点击clone按钮后,会弹出如下截图弹窗,点击 NO 项目已经拉取到本地,然后点击ope ...
- hanjiaqi
2017*1501:我是韩佳琦:我的爱好是睡觉: 我的码云个人主页是:https://gitee.com/projects/new 我的第一个项目地址是:https://gitee.com/hanji ...