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 ...
随机推荐
- 判断一个数组是否包含一个指定的值 includes-ES6
var array1 = [1, 2, 3]; console.log(array1.includes(2)); // trueconsole.log(array1.includes(2, 5)); ...
- 【 hibernate 】基本配置
hibernate.cfg.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibe ...
- 【SSM】AppFileUtils
11 package com.kikyo.sys.utils; import java.io.File; import java.io.IOException; import java.io.Inpu ...
- nginx windows下重新加载配置
运行过程中,有个节点部分服务出现故障,像将其下线修复, 使用nginx -t; nginx -s reload 重新加载配置 得到错误"nginx: [error] OpenEvent(&q ...
- 复盘实战营一期毕业典礼----HHR计划----以太入门课--第一课
你要永远记住,实事求是. 我好像没能力给大家分享什么.分享点我的专业知识吧.我是做推荐+增长的,在一家D轮 DAU快千万的创业公司做增长优化负责人.一路优化,我把人均时长提高了30多分钟(现在人均时长 ...
- HHR计划---作业复盘-直播第三课
一,出租车广告: 1,三个点不合格:周期太长了,大而全互联网产品,不符合MVP原则:业务关键点丢掉了:没有业务认知和成长. 2,关键假设: (1)车主有没有需求呀,画像怎么样? (2)车主收入如何,能 ...
- GO闭包
package main import "fmt" func main() { add_func := add(1,2) fmt.Println(add_func(1,1)) fm ...
- 吴裕雄--天生自然TensorFlow2教程:误差计算
import tensorflow as tf y = tf.constant([1, 2, 3, 0, 2]) y = tf.one_hot(y, depth=4) # max_label=3种 y ...
- 吴裕雄--天生自然ORACLE数据库学习笔记:常用SQL*Plus命令
set pause on set pause '按<enter>键继续' select user_id,username,account_status from dba_users; sh ...
- Unity表面着色器
表面着色器和之前无光照着色器不同,其中没有顶点着色器和片元着色器,而增加了光照函数: 接下写了一个求两个贴图的光照效果 两个贴图做插值运算: Shader "Custom/SurfaceSh ...