我的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的学习笔记.原理分析.使用例程等相关的博文.排序不分先后,随机整理的 ...
随机推荐
- netcore 下加密遇到的问题
KeyedHashAlgorithm algorithm = KeyedHashAlgorithm.Create(algorithmName.ToString().ToUpper(CultureInf ...
- JS的基本(原始)数据类型
1.boolean true & false 2.null 空值类型 3.undefined 未定义类型 4.number 数值类型 5.string 字符串类型 6.sy ...
- nginx入门之编译安装
nginx是什么 nginx是一个开源的,支持高性能,高并发的www服务和代理服务软件.它是一个俄罗斯人lgor sysoev开发的,作者将源代码开源出来供全球使用. nginx比它大哥apache性 ...
- ABAP 程序/接口调用其他程序的数据
在ABAP遇到的业务场景中,可能会遇到一种情况,需要调用其他报表的数据来发送或者二次加工,这个时候又不想对源程序做大的改动.有以下几种思路解决. 1.修改源程序,将需要展示的数据存储到DB中,然后主程 ...
- d3.js svg中 g 标签问题一览
svg 中的g标签, 算是比较特殊 1 没有x y属性 2 没有width height 属性 3 不能fill 4 .... g标签基本只管分组问题, 其他功能一概不提供 要解决这些问题, 直接在g ...
- 自制EF(iShare Demo版)
由于公司使用的所有技术都比较倾向于使用原生,不怎么借用其他第三方框架(无论是前端布局,样式,到后台的框架).公司也算比较小型的没有太大的项目 可以让我们进行团队合作项目,几乎是一人接手一个项目.然后自 ...
- 【题解二连发】Construct Binary Tree from Inorder and Postorder Traversal & Construct Binary Tree from Preorder and Inorder Traversal
LeetCode 原题链接 Construct Binary Tree from Inorder and Postorder Traversal - LeetCode Construct Binary ...
- 记第一次XSS实战
前两天偶然挖到一个XSS,在我低谷期的时候给了我些动力,遂写下这篇博客记录 随手在一个搜索框中测试,发现有反应 观察一下标签,需要">把前面的闭合,然后<a 把后面的标签闭合 结 ...
- Java中的equals和hashCode方法详解
Java中的equals和hashCode方法详解 转自 https://www.cnblogs.com/crazylqy/category/655181.html 参考:http://blog.c ...
- Ambari2.6.2 HDP2.6.5 大数据集群搭建
Ambari 2.6.2 中 HDFS-2.7.3 YARN-2.7.3 HIVE-1.2.1 HBASE-1.1.2 ZOOKEEPER-3.4.6 SPARK-2.3.0 注:本文基于root用户 ...