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 ...
随机推荐
- 洛谷P1144最短路计数
题目描述 给出一个NNN个顶点MMM条边的无向无权图,顶点编号为1−N1-N1−N.问从顶点111开始,到其他每个点的最短路有几条. 输入格式 第一行包含222个正整数N,MN,MN,M,为图的顶点数 ...
- 杭电 2013 猴子吃桃 递归解法&循环解法
题目估计看到过3次不止了,所以还是想复习下递归的运用. 奉上递归代码: #include <iostream> #include<math.h> #include <io ...
- jquery 分页 Ajax异步
//使用Ajax异步查询数据 <div class="table-responsive"> <table class="table table-bord ...
- 「CF197B Limit」
题目撞名 题目大意: 给出两个函数 \(P(x),Q(x)\). \(P(x)=a_0 \times x^N+a_1 \times x^{N-1}+a_2 \times x^{N-2} \cdots ...
- 对FPM 模块进行参数优化!
Nginx 的 PHP 解析功能实现如果是交由 FPM 处理的,为了提高 PHP 的处理速度,可对FPM 模块进行参数跳转.FPM 优化参数:pm 使用哪种方式启动 fpm 进程,可以说 static ...
- 用java代码打印九九乘法表
package com.wf; public class cal { public static void main(String[] args) { for(int i=1;i<10;i++) ...
- 区分移动端和pc端
区分移动端和pc端: window.navigator.userAgent.toLowerCase().indexOf('mobile')== -1 判断 等于-1就是pc,false就是移动端 ...
- 「JSOI2014」歌剧表演
「JSOI2014」歌剧表演 传送门 没想到吧我半夜切的 这道题应该算是 \(\text{JSOI2014}\) 里面比较简单的吧... 考虑用集合关系来表示分辨关系,具体地说就是我们把所有演员分成若 ...
- selenium webdriver 实现百度贴吧自动签到
public static void main(String[] args) { //TestUtils.killProcess("javaw.exe"); TestUtils.k ...
- getopts以参数形式执行diag
#!/bin/bash ################################################################################# # Copy ...