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 ...
随机推荐
- 【转】弹出USB大容量存储设备时出问题的解决方法
原文链接 如下图所示,这个问题,相信很多人都有遇到过,而且经常难以解决,试了很多方法都无效.到最后,只能抱着侥幸的心理直接拔出,如果运气好,可能没有事,如果运气不好,你的U盘或者移动硬盘就要从此报废了 ...
- springcloud-zuul初级篇
一 前言 zuul路由网关的核心作用是用于后台服务的统一管理:由于微服务是部署在多台服务器上,服务器的ip地址并不能统一,我们需要暴露一个统一的ip地址给前台使用进行接口调用:zuul就是起到路由网关 ...
- leetCode练题——9. Palindrome Number
1.题目 9. Palindrome Number Determine whether an integer is a palindrome. An integer is a palindrome ...
- 教育片- Economics by Crash Course(共35集)(未完结)
第一集Intro to Economics: Crash Course Econ #1 传送门:https://www.youtube.com/watch?v=3ez10ADR_gM&list ...
- laravel 排除csrf验证
中(*排除所有路由)
- selenium webdriver 执行Javascript
@Test public void testElementByID() { //通过JS获取页面元素 driver.get(url); driver.manage().window().maximiz ...
- 关于热部署Devtools出现同一个类型进行类型转换失败的问题
背景: 最近在和学长们做一个小系统,在进行任务调度的设置的时候会出现类型转换失败的错误,原本是同一个类型的,不应该出现类型转换失败的问题,起初以为是序列化的问题,回来发现并不是这个原因, 报错截图: ...
- Spring学习(四)
Spring Ioc容器 1.具有依赖注入功能的容器.负责实例化,定位,配置应用程序中的对象及建立这些对象间的依赖.在Spring中BeanFactory是Ioc容器的实际代表者.BeanFactor ...
- Codeforces #617 (Div. 3) D. Fight with Monsters(贪心,排序)
There are nn monsters standing in a row numbered from 11 to nn . The ii -th monster has hihi health ...
- Spark教程——(8)本地执行spark-sql程序
在程序中设定Spark SQL的运行模式: //.setMaster("local")设置本地运行模式 val conf = new SparkConf().setAppName( ...