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 ...
随机推荐
- C语言中的位操作(15)--确定log10(N)的整数部分
本篇文章介绍一个整数的以10为底的对数的整数部分,即对于整数N,求log10(N)整数部分 方法一 : unsigned int v; //32位非0整数 int r; // r保存结果 int t; ...
- electron—Chromium有酒,Node有肉
谷歌V8引擎的出现,Node.js的诞生注定要把开发模式“搅乱”. 基于云应用,服务化,定制化的应用需求不断增加后使得传统的winform开发空间越来越小,而原来做前端的空间越来越大,Node.js ...
- 初识JQuery(1)-选择器
初识jquery 在学习jquery之前,就有看过一些相关的视频,才知道它是可以写很少的代码就可以完成很多事的.记得第一写轮播图的时候,首先就百度了篇轮播图的实现,当时还不知道自己百度的其实不是原生的 ...
- ES _all、_source的使用——_all字段连接所有字段的值构成一个用空格(space)分隔的大string而被analyzed和index,document主体保存在_source中
1._all 1.1_all field _all字段是一个很少用到的字段,它连接所有字段的值构成一个用空格(space)分隔的大string,该string被analyzed和index,但是不被s ...
- 绘图工具--turtle模块
turtle模块主要使用两个类,一个是TurtleScreen类,表示画布(窗口),用来展示画的位置:一个是Turtle类,用来充当画笔,用来画. 两个类的方法也以同名的函数的形式存在,所以可以以面向 ...
- python遍历并获取对象属性--dir(),__dict__,getattr,setattr
一.遍历对象的属性: 1.dir(obj) :返回对象的所以属性名称字符串列表(包括属性和方法). for attr in dir(obj): print(attr) 2.obj.__dict__:返 ...
- log4net初探
/// <summary> /// Static constructor that initializes logging by reading /// settings from the ...
- CF 360 E Levko and Game —— 贪心+最短路
题目:http://codeforces.com/contest/360/problem/E 首先,每条边不是选 \( l[i] \) 就是选 \( r[i] \): 做法就是先把边权都设成 \( r ...
- 如何在开启了log-bin的MySQL Server中创建FUNCTION
在MySQL主从复制机器的master的数据库中创建function,报出如下错误: Error Code: 1418. This function has none of DETERMINISTIC ...
- Poj 3356 ACGT(LCS 或 带备忘的递归)
题意:把一个字符串通过增.删.改三种操作变成另外一个字符串,求最少的操作数. 分析: 可以用LCS求出最大公共子序列,再把两个串中更长的那一串中不是公共子序列的部分删除. 分析可知两个字符串的距离肯定 ...