我的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的学习笔记.原理分析.使用例程等相关的博文.排序不分先后,随机整理的 ...
随机推荐
- 【转】How to initialize a two-dimensional array in Python?
[wrong way:] m=[[element] * numcols] * numrows for example: >>> m=[['a'] *3] * 2>>> ...
- python os.path.isfile函数
最近刚开始学习Python,做了个小练习:扫描当前目录及其子目录中的文件,找出文件名中含有指定关键字的文件并打印文件名.思路很简单,如果是文件则判断是否满足条件:如果是目录则进入目录搜索文件,递归. ...
- JVM、redis缓存适用场景
1. 数据状态相对稳定:(针对数据本身)数据修改较少. 2. 输出的数据是相对幂等:(针对业务)多次查询期间,数据不变动.如果查询频率过高,缓存可能没有及时更新. 了解一下redis.ehcache. ...
- Python来袭,教你用Neo4j构建“复联4”人物关系图谱!
来源商业新知网,原标题:Python来袭,教你用Neo4j构建“复联4”人物关系图谱!没有剧透! 复仇者联盟 之绝对不剧透 漫威英雄们为了不让自己剧透也是使出了浑身解数.在洛杉矶全球首映礼上记者费尽心 ...
- 移动端目标识别(3)——使用TensorFlow Lite将tensorflow模型部署到移动端(ssd)之Running on mobile with TensorFlow Lite (写的很乱,回头更新一个简洁的版本)
承接移动端目标识别(2) 使用TensorFlow Lite在移动设备上运行 在本节中,我们将向您展示如何使用TensorFlow Lite获得更小的模型,并允许您利用针对移动设备优化 ...
- Taro开发之城市选择器(带坐标)
要写个城市选择器能返回对应的城市(这里只定义到了地级市),同时返回坐标系,参考了网上资料,下面就看看具体代码吧 import Taro, { Component } from '@tarojs/tar ...
- python中的函数和变量
本节内容 函数的定义方法 函数功能 函数的返回值 函数的形参与实参 全局变量与局部变量 递归 函数的作用域 匿名函数lambda 函数式编程 常用内置函数 其他内置函数 函数 函数的定义方法 函数就相 ...
- yii2-redis 扩展详解
安装yii2-redis composer require yiisoft/yii2-redis 修改config/web.php 的 components 配置 'cache' => [ / ...
- IDEA 中tomcat日志位置
参考 https://blog.csdn.net/dela_/article/details/78555977 /home/dela/.IntelliJIdea2017.1/system/tomcat ...
- selenium调用webdriver异常
使用selenium调用webdriver的时候报错. from selenium import webdriver browser = webdriver.Chrome() browser.get( ...