Unity -- AssetBundle(本地资源加载和加载依赖关系)
1.本地资源加载
1).建立Editor文件夹
2).建立StreamingAssets文件夹和其Windows的子文件夹
将下方第一个脚本放入Editor 里面
脚本一 资源打包AssetBundle的所有标签资源
using UnityEngine;
using UnityEditor; public class Tools
{
[MenuItem("Tools/buildAB")] //编辑器扩展
public static void Building()
{
Debug.LogError("");
string _adPath = Application.streamingAssetsPath + "\\Windows";//路径
BuildPipeline.BuildAssetBundles(_adPath, BuildAssetBundleOptions.None, BuildTarget.StandaloneLinux64);
//自动检测有AssetBundle标签的预制体,并进行资源压缩. //固定格式
} }
资源加载
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class Load2 : MonoBehaviour { // Use this for initialization
void Start ()
{
//本地必须加入 file:// 这样子www才能进行访问
string _abpath ="file://" +Application.streamingAssetsPath + "/Windows/sp"; StartCoroutine("Creat",_abpath);
}
// Update is called once per frame
void Update ()
{
}
IEnumerator Creat(string path)
{
using (WWW lo=new WWW(path))
{
yield return lo;
if (lo != null)
{
AssetBundle ab = lo.assetBundle;
if (ab != null)
{
GameObject obj = ab.LoadAsset<GameObject>("Cube");
Instantiate(obj);
}
}
else {
Debug.LogError("加载失败");
}
}
}
2.加载依赖关系
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LoadManCtr : MonoBehaviour {
// Use this for initialization
public string ABName;
string _abPath;
string _manpath;
private List<AssetBundle> ManListAB;
void Start ()
{
ManListAB = new List<AssetBundle>();
_abPath = Application.streamingAssetsPath + "/Windows/";
_manpath = Application.streamingAssetsPath + "/Windows/Windows";
//查找依赖关系
#region 加载依赖
AssetBundle _manAB = AssetBundle.LoadFromFile(_manpath);
//固定格式
AssetBundleManifest manifest = _manAB.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
string[] dependencies = manifest.GetAllDependencies(ABName);
Debug.LogError(dependencies.Length);
//加载依赖
if (dependencies.Length != )
{
foreach (string s in dependencies)
{
Debug.Log(s);
//挨个加载依赖关系
ManListAB.Add(LoadABByName(s)); //存在内存中
}
}
#endregion
//依赖加载完毕 圆柱 立方体
AssetBundle _ab = AssetBundle.LoadFromFile(_abPath + ABName);
GameObject copyObj = _ab.LoadAsset<GameObject>("Capsule");
Instantiate(copyObj);
//释放ab依赖的内存
foreach (var v in ManListAB)
{
v.Unload(false);
}
_ab.Unload(false);//不从场景里面删除
//true 场景删除
AssetBundle _ab01 = AssetBundle.LoadFromFile(_abPath + ABName);//_ab.Unload(false); 没有这句话会重复加载
GameObject copyObj01 = _ab01.LoadAsset<GameObject>("Capsule");
Instantiate(copyObj01,Vector3.one,Quaternion.identity);
}
// Update is called once per frame
void Update ()
{
}
private AssetBundle LoadABByName(string name)
{
return AssetBundle.LoadFromFile(_abPath + name);
}
}
Unity -- AssetBundle(本地资源加载和加载依赖关系)的更多相关文章
- Flutter 开发从 0 到 1(四)ListView 下拉加载和加载更多
在<APP 开发从 0 到 1(三)布局与 ListView>我们完成了 ListView,这篇文章将做 ListView 下拉加载和加载更多. ListView 下拉加载 Flutter ...
- Unity 4.x 资源加载
using UnityEngine; using System.Collections; using System.IO; public class LoadResource : MonoBehavi ...
- 浏览器如何对HTML5的离线储存资源进行管理和加载
在线的情况下,浏览器发现html头部有manifest属性,它会请求manifest文件,如果是第一次访问app,那么浏览器就会根据manifest文件的内容下载相应的资源并且进行离线存储.如果已经访 ...
- [Unity AssetBundle]Asset资源处理
什么是AssetBundle 在很多类型游戏的制作过程中,开发者都会考虑一个非常重要的问题,即如何在游戏运行过程中对资源进行动态的下载和加载.因此,Unity引擎引入了AssetBundle这一技术来 ...
- Unity AssetBundle 游戏资源分类及关系
--刚刚做完一个xlua的的热更项目,对AssetBundle资源分类总结一下.纯理论,闲谈知识,要是有建议,尽管提 ,不掺杂代码. --这里说说,AB是如何打包,如果下载,如何加载. 1.关键词理解 ...
- Unity5 AssetBundle系列——资源加载卸载以及AssetBundleManifest的使用
下面代码列出了对于assetbundle资源的常用操作,其中有针对bundle.asset.gameobject三种类型对象的操作,实际使用中尽量保证成对使用. 这一块的操作比较繁琐,但只要使用正确, ...
- Unity AssetBundle打包资源工具
using UnityEngine;using System.Collections;using UnityEditor; /// <summary>/// 简单资源打包Editor/// ...
- js根据顺序加载,有依赖关系
function loadScript(url, callback) { var script = document.createElement("script"); script ...
- Unity最新版打包AssetBundle和加载的方法
一.设置assetBundleName二.构建AssetBundle包三.上传AssetBundle到服务器四.把AssetBundle放到本地五.操作AssetBundle六.完整例子七.Asset ...
随机推荐
- Windows下控制Nginx的状态
Windows下Nginx的启动.停止等命令 在Windows下使用Nginx,我们需要掌握一些基本的操作命令,比如:启动.停止Nginx服务,重新载入Nginx等,下面我就进行一些简单的介绍.1.启 ...
- 2015年SCI收录遥感期刊28种目录
链接地址:http://blog.sciencenet.cn/blog-57081-928025.html
- 简单封装的Log4net
1. [代码]使用 log = new Logger(this.GetType());log.Info("Hello world.");2. [代码]第二个版本,修复了Co ...
- Luogu P1463 [HAOI2007]反素数ant:数学 + dfs【反素数】
题目链接:https://www.luogu.org/problemnew/show/P1463 题意: 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4. 如果某个正整数x ...
- (转)edm注意事项
格式编码 1.页面宽度请设定在600到800px以内,长度1024px以内. 2.HTML编码请使用utf-8. 3.HTML代码在15KB以内.(各个邮箱的收件标准不一样,如果超出15KB您的邮件很 ...
- Eclipse 下配置MySql5.6的连接池,使用Tomcat7.0
目前找到的最简单的配置方法. 1.首先在eclipse中创建一个Dynamical Web Application,在WebContent文件夹下的META-INF文件夹中创建新的名为conten ...
- delphi完美经典-第16章 Delphi数据库程序设计----使用BDE组件
第16章 Delphi数据库程序设计----使用BDE组件 Delphi访问数据库的方式有:ADO.BDE.dbExpress.InterBase Express. 一.TDataSet组件 虽然De ...
- java_面试_01_一个月的面试总结(java)
重点知识 由于我面试的JAVA开发工程师,针对于JAVA,需要理解的重点内容有: JVM内存管理机制和垃圾回收机制(基本每次面试都会问,一定要搞得透彻) JVM内存调优(了解是怎么回事,一般做项目过程 ...
- hsv空间
hsv在不同的软件中,有不同的阈值, 在描述阈值之前,看一下它的定义,按照标准的定义,hsv应该是从0°到360°的一个环,加上一个表示亮度的轴,重点就是那个环. 这个环如图一,0°一般为红色120° ...
- Havel-Hakimi定理(握手定理)
Havel-Hakimi定理(握手定理) 由非负整数组成的非增序列s(度序列):d1,d2,…,dn(n>=2,d1>=1)是可图的,当且仅当序列: s1:d2 – 1,d3 – 1,…, ...