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打包依赖(宽宽又欠我一顿烧烤)的更多相关文章

  1. Unity5.x版本AssetBundle打包研究

    Unity5的AssetBundle打包机制和以前版本不太一样.简单的说就是,只要给你要打包的资源设置一个AssetBundleName ,Unity自身会对这些设置了名字的资源进行打包,如果一个资源 ...

  2. [Unity3d][NGUI]两种思路解决AssetBundle的依赖关系.

    接上文. 使用上文中的AssetBundle打包方式生成的文件包括了依赖关系中的文件. 一般的使用中并不会发现什么问题. 可是当配合NGUI的时候,使用dynamicFont时打包AssetBundl ...

  3. Unity3d 5.x AssetBundle打包与加载

    1.AssetBundle打包 unity 5.x版本AssetBundle打包,只需要设置好AssetBundle的名称后,unity会自动将其打包,无需处理其他,唯独需要做的是设置好个AssetB ...

  4. AssetBundle打包

    为热更新打基础(xlua\tolua) 素材.源码链接:http://www.sikiedu.com/course/74/task/1812/show 一.AssetBundle的定义和作用 1,As ...

  5. 一个灵活的AssetBundle打包工具

      尼尔:机械纪元 上周介绍了Unity项目中的资源配置,今天和大家分享一个AssetBundle打包工具.相信从事Unity开发或多或少都了解过AssetBundle,但简单的接口以及众多的细碎问题 ...

  6. AssetBundle打包详解

    Unity5.x AssetBundle打包详解 在网上查看了很多资料,想详细搞清楚AssetBundle的原理.以实现符合项目需求的打包工具和加载逻辑 1. AssetBundle是什么? Asse ...

  7. unity3d assetbundle打包策略

    由于assetbundle打包存在依赖的问题,所有资源要进行合理的分包 零.代码 代码都放在本地,包括NGUI等插件的代码.shader代码(内置的shader无需打包,而自定义的shader还是需要 ...

  8. (转)[Unity3D]BuildPipeline.PushAssetDependencies 打包依赖包,优化UI Prefab的资源引用加载(坑爹之处)

    转自:http://blog.csdn.net/chiuan/article/details/39040421#reply 1:长话短说,UI Prefab中一般会交叉引用Atlas,那么打包时候我们 ...

  9. Unity5 AssetBundle打包加载及服务器加载

    Assetbundle为资源包不是资源 打包1:通过脚本指定打包 AssetBundleBuild ab = new AssetBundleBuild                         ...

随机推荐

  1. CRS-1硬件维护

    一.CRS-1硬件介绍CRS-1 路由器是Cisco 推出的新的大容量骨干路由器,是一个支持多机箱扩展的路由系统.其设计容量可以扩展至72 个线卡机箱.8 个矩阵机箱,总交换容量达到92Tbps,具有 ...

  2. 【原】简单shell练习(六)

    1.shell获取进程号并杀掉该进程 kill - $(ps -ef | grep node| grep -v grep | awk '{print $2}') 解析: ps (processStat ...

  3. 【docker问题】Client.Timeout exceeded while awaiting headers

    在进行docker pull 拉取镜像时,出现过下面的错误: net/http: request canceled while waiting for connection (Client.Timeo ...

  4. linux(centos6.10)下去掉mysql的强密码验证

    vim /etc/my.cnf shift + G      光标移到最下方: o    进入插入模式,同时换行: 添加一行语句:  validate_password=OFF 保存退出. servi ...

  5. matlab练习程序(传染病模型)

    最近新型冠状病毒疫情越来越严重了,待在家中没法出去,学习一下经典传染病模型. 这里总结了五个模型,分别是SI模型,SIS模型,SIR模型,SIRS模型,SEIR模型. 这几种模型的特点先介绍一下. 首 ...

  6. Django 学习之Rest Framework 视图集与Routers与扩展功能

    一.视图集使用 使用视图集ViewSet,可以将一系列逻辑相关的动作放到一个类中: list() 提供一组数据 retrieve() 提供单个数据 create() 创建数据 update() 保存数 ...

  7. uniGUI之通过URL控制参数(25)

    通过URL代入参数,在代码中读取,如: http://localhost:8077/?ServerPort=212&&ServerIP=192.168.31.12 procedure ...

  8. 实现纸牌游戏的随机抽牌洗牌过程(item系列几个内置方法的实例)

    实现纸牌游戏的随机抽牌洗牌过程(item系列几个内置方法的实例) 1.namedtuple:命名元组,可以创建一个没有方法只有属性的类 from collections import namedtup ...

  9. 1146. Snapshot Array

    Implement a SnapshotArray that supports the following interface: SnapshotArray(int length) initializ ...

  10. python脚本调用iftop 统计业务应用流量

    因公司服务器上部署应用较多,在有大并发访问.业务逻辑有问题的情况下反复互相调用或者有异常流量访问的时候,需要对业务应用进行故障定位,所以利用python调用iftop命令来获取应用进程流量,结合zab ...