AssetBundle打包依赖(宽宽又欠我一顿烧烤)
using UnityEngine;
using System.Collections;
using UnityEditor;
public class dabao : EditorWindow
{
/*
* 主要就这俩东西 - -、
*BuildPipeline.PushAssetDependencies():依赖资源压栈; BuildPipeline.PopAssetDependencies():依赖资源出栈。
*/
[MenuItem("z/make")]
static void CreateAssetBunldesMain_exe()
{
BuildPipeline.PushAssetDependencies();
Object Ztexture = Resources.Load("z");
string path = Application.dataPath + "/StreamingAssets/z.bytes";
BuildPipeline.BuildAssetBundle(Ztexture, null, path, BuildAssetBundleOptions.CollectDependencies); Object[] SelectedAsset = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
foreach (Object obj in SelectedAsset)
{
BuildPipeline.PushAssetDependencies();
string targetPath = Application.dataPath + "/StreamingAssets/" + obj.name + ".bytes";
BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies);
BuildPipeline.PopAssetDependencies(); } BuildPipeline.PopAssetDependencies();
//刷新编辑器
AssetDatabase.Refresh();
} }
打包代码完成的功能是: 先把选中预设们公用的那个贴图打包了。然后再打包选中的这几个预设(贴图名字是“z”,预设们名字是 t1和t2)通过push压栈和pop出栈来隔离开,内层可以包含外层的引用,但不包含外层的资源本身。
加载代码的逻辑是:为了试验一下是否有依赖关系,先加载预设t2,等确保加载出来之后,再加载贴图z,等确保加载完贴图之后,再加载预设t1。最后会发现t1上有贴图,而t2上没有贴图。(这个代码编写的逻辑并不好,只是通过协程来挂起时间。但是用来实验还是不错吧~~~~所以 在加载预设之前,必须先把他们引用到的资源加载上)
QQ 745701540
using UnityEngine;
using System.Collections; public class jiazai : MonoBehaviour
{ IEnumerator Start()
{
Caching.CleanCache(); #region 无贴图实验
StartCoroutine(Load("file://" + Application.dataPath + "/StreamingAssets/t2.bytes"));
yield return new WaitForSeconds();
#endregion #region 贴图实验
StartCoroutine(LoadTP());//加载贴图
yield return new WaitForSeconds();
StartCoroutine(Load("file://" + Application.dataPath + "/StreamingAssets/t1.bytes")); #endregion } IEnumerator LoadTP()
{
string path = "file://" + Application.dataPath + "/StreamingAssets/z.bytes";
WWW bundle = WWW.LoadFromCacheOrDownload(path, );
yield return bundle;
} private IEnumerator Load(string path)
{
WWW bundle = WWW.LoadFromCacheOrDownload(path, );
yield return bundle;
if (bundle != null)
{
//加载到游戏中
Instantiate(bundle.assetBundle.mainAsset);
} }
}
这种方式打包之后的三个包的大小(一个贴图 俩预设)

最简单粗暴的打包那俩预设的大小(俩预设)

哎呦不错喔足足小了一个贴图z的资源大小呀~
另外,忽然发现jpg啊等等的图片打包还不如不打包....越打越大,所以直接把它扔streamAsset里去,然后加载贴图比较好吧大概。
AssetBundle打包依赖(宽宽又欠我一顿烧烤)的更多相关文章
- Unity5.x版本AssetBundle打包研究
Unity5的AssetBundle打包机制和以前版本不太一样.简单的说就是,只要给你要打包的资源设置一个AssetBundleName ,Unity自身会对这些设置了名字的资源进行打包,如果一个资源 ...
- [Unity3d][NGUI]两种思路解决AssetBundle的依赖关系.
接上文. 使用上文中的AssetBundle打包方式生成的文件包括了依赖关系中的文件. 一般的使用中并不会发现什么问题. 可是当配合NGUI的时候,使用dynamicFont时打包AssetBundl ...
- Unity3d 5.x AssetBundle打包与加载
1.AssetBundle打包 unity 5.x版本AssetBundle打包,只需要设置好AssetBundle的名称后,unity会自动将其打包,无需处理其他,唯独需要做的是设置好个AssetB ...
- AssetBundle打包
为热更新打基础(xlua\tolua) 素材.源码链接:http://www.sikiedu.com/course/74/task/1812/show 一.AssetBundle的定义和作用 1,As ...
- 一个灵活的AssetBundle打包工具
尼尔:机械纪元 上周介绍了Unity项目中的资源配置,今天和大家分享一个AssetBundle打包工具.相信从事Unity开发或多或少都了解过AssetBundle,但简单的接口以及众多的细碎问题 ...
- AssetBundle打包详解
Unity5.x AssetBundle打包详解 在网上查看了很多资料,想详细搞清楚AssetBundle的原理.以实现符合项目需求的打包工具和加载逻辑 1. AssetBundle是什么? Asse ...
- unity3d assetbundle打包策略
由于assetbundle打包存在依赖的问题,所有资源要进行合理的分包 零.代码 代码都放在本地,包括NGUI等插件的代码.shader代码(内置的shader无需打包,而自定义的shader还是需要 ...
- (转)[Unity3D]BuildPipeline.PushAssetDependencies 打包依赖包,优化UI Prefab的资源引用加载(坑爹之处)
转自:http://blog.csdn.net/chiuan/article/details/39040421#reply 1:长话短说,UI Prefab中一般会交叉引用Atlas,那么打包时候我们 ...
- Unity5 AssetBundle打包加载及服务器加载
Assetbundle为资源包不是资源 打包1:通过脚本指定打包 AssetBundleBuild ab = new AssetBundleBuild ...
随机推荐
- iOS 上通过 802.11k、802.11r 和 802.11v 实现 Wi-Fi 网络漫游
在 iOS 上通过 802.11k.802.11r 和 802.11v 实现 Wi-Fi 网络漫游 了解 iOS 如何使用 Wi-Fi 网络标准提升客户端漫游性能. iOS 支持在企业级 Wi-Fi ...
- 杭电 2136 Largest prime factor(最大素数因子的位置)
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- AngularJS学习:第一个demo
1. 引入angular.js 相应版本下载地址: https://code.angularjs.org/ 2. 编写html <!DOCTYPE html> <html> & ...
- [总结]一些 DP 优化方法
目录 注意本文未完结 写在前面 矩阵快速幂优化 前缀和优化 two-pointer 优化 决策单调性对一类 1D/1D DP 的优化 \(w(i,j)\) 只含 \(i\) 和 \(j\) 的项--单 ...
- windows下安装elasticsearch-6.4.3和elasticsearch-head插件
windows下安装elasticsearch-6.4.3和elasticsearch-head插件 博客分类: elasticsearch es ElasticSearch下载地址:https:/ ...
- Git - 删除github上的提交历史
参考 https://segmentfault.com/q/1010000002898735 https://stackoverflow.com/questions/1338728/delete-co ...
- NSDateFormatter使用注意事项
NSDateFormatter是用来连接NSDate和NSString之间的桥梁 它的使用方式,不(自)做(行)说(百)明(度) 要说的注意事项就是,NSString转NSDate时,NSDateFo ...
- 吴裕雄--天生自然PythonDjangoWeb企业开发:需求
开发或者做一个项目,是要有一个需求过来的,而不是无缘无故的,启动一个项目,或者推动整个项目进行下一步迭代.这个需求可能是根据用户反馈增加的,可能是老板提出来的,也有可能是产品经理提出来的,但是无论是什 ...
- ApacheDbUtilsUpdate
ApacheDbUtilsUpdate package p1; import com.DataSourceUtil; import org.apache.commons.dbutils.QueryRu ...
- Linux centos7VMware Apache和PHP结合、Apache默认虚拟主机
一.Apache和PHP结合 httpd主配置文件/usr/local/apache2.4/conf/httpd.conf 启动报错 [root@davery ~]# /usr/local/apach ...