buildpipeline.buildassetbundle过时 已过时 怎么办

AssetBundle入门 - 坚信移动技术可以改变我们的生活方式 - ITeye博客
博客分类:
MB525defy Android 2.2.1
羽化的第二十六篇博客,春节回来后工作就十分繁忙,一直没时间来整理博客,升级到了没遇到任何问题,新功能中粒子系统很有趣,以后写篇博客研究下最近在整理这个下载规则的时候才能写一篇关于打包下载的博客,只能给大家做参考,没多少技术含量,真正复杂的的是如何在智能化上。就羽化目前接触的网页游戏而言,很多都是以一个为单位来打包,或者是来打包,这种作法很方便,但不够完美,有一套完整的加载和打包结构才是最佳的网页解决方案。
PSV看来很吸引人可惜买不起。。。末期大作中最终幻想零式素质惊人,说是上最强游戏绝对无可厚非,在进化最终幻想同时,也进化了的表现形式,大部分人接受了时代的变迁,少部分人沉浸在旧时的游戏中,但不可否认的事,游戏慢慢成了最佳的艺术表现形式。
2012年月日这种特殊的节日适合发生一些特殊的事,时光荏苒不知道能不能用上,只知道这几年,自己从未改变,以后估计也不会改变,拖着这个沉重的身躯,也要赶上这个过快的世界,虽然才离开家不久,但又开始想家了,可惜有段时间回不去了。
本次学习:
简介物件组成
AssetBundle
打包和读取
1.简介物件组成
这是羽化做的一个粗略图,其中各个组成部分除了工程以外都能通过AssetBundle打成一个后缀名为.unity3d的外部资源包,通过Unity自身的高压技术,最多能节约60%~70%的资源容量。
2.AssetBundle
官方有自带的的例子,羽化通过这个例子改成了自己的一个小工程,通过AssetBundle的打包处理的好处在于把自身的依赖关系包括数据结构合理的分配完整,这样不需要开发者自己去给下载或者加载的资源控制路径,大大降低了开发大型在线游戏的门槛,同时越来越细的封包可以减少游戏的总体大小,资源最大化利用,对于小游戏也带来了很大帮助,可惜按照官方的说法是目前不能完全支持移动端。
AssetBundle具体使用方法在手册上写得很详细,圣典里也有详细的中文说明,羽化就不多说废话,需要注意的是AssetBundle的读取,虽然资源基本上都是用简单读取,但在特殊情况下会去读取特定unity3d包中的特定贴图,或者说是模型,这里就必须注意打包的结构,因为读取出来的是一个Object数组,可以使用Load读取特定资源。
3. 打包和读取
打包方式是在Project视图下选择AutomatedExportResources,过程是自动完成,Unity的Editor类中提供了很多有趣的方法可以实现不同的打包操作,官方只给了手选打包和自动打包两种,但都不够智能。
AutomatedExportResources.js
[javascript]
&span style="font-size:16"&@MenuItem("Assets/Auto Build Resource Files")
static function ExportResource ()
System.IO.Directory.CreateDirectory("AssetBundles");
var options = BuildAssetBundleOptions.CollectDependencies | pleteA
BuildPipeline.PushAssetDependencies();
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Standard Assets/Data/Texture/Effects/Hit/Hit1.tga"), null, "AssetBundles/Data/Texture/Effects/Hit/Hit1.unity3d", options);
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Standard Assets/Data/Texture/Effects/Hit/Hit2.tga"), null, "AssetBundles/Data/Texture/Effects/Hit/Hit2.unity3d", options);
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Standard Assets/Data/Model/Effects/Hit/Hit1.fbx"), null, "AssetBundles/Data/Model/Effects/Hit/Hit1.unity3d", options);
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Standard Assets/Data/Model/Effects/Hit/Hit2.fbx"), null, "AssetBundles/Data/Model/Effects/Hit/Hit2.unity3d", options);
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Standard Assets/Data/Material/Effects/Hit/Hit1.mat"), null, "AssetBundles/Data/Material/Effects/Hit/Hit1.unity3d", options);
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Standard Assets/Data/Material/Effects/Hit/Hit2.mat"), null, "AssetBundles/Data/Material/Effects/Hit/Hit2.unity3d", options);
BuildPipeline.PushAssetDependencies();
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Standard Assets/Data/Prefab/Effects/Hit/Hit1.prefab"), null, "AssetBundles/Data/Prefab/Effects/Hit/Hit1.unity3d", options);
BuildPipeline.PopAssetDependencies();
BuildPipeline.PushAssetDependencies();
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Standard Assets/Data/Prefab/Effects/Hit/Hit2.prefab"), null, "AssetBundles/Data/Prefab/Effects/Hit/Hit2.unity3d", options);
BuildPipeline.PopAssetDependencies();
BuildPipeline.PushAssetDependencies();
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Standard Assets/Data/Prefab/Effects/Hit/Hit3.prefab"), null, "AssetBundles/Data/Prefab/Effects/Hit/Hit3.unity3d", options);
BuildPipeline.PopAssetDependencies();
BuildPipeline.PushAssetDependencies();
BuildPipeline.BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("Assets/Standard Assets/Data/Prefab/Effects/Hit/Hit3.prefab"), null, "AssetBundles/Data/Prefab/Effects/Hit/Hit3.unity3d", options);
BuildPipeline.PopAssetDependencies();
BuildPipeline.PopAssetDependencies();
这是羽化的打包代码,可以看出羽化做了一个两层依赖,当然可以做更多,但写起也就更加复杂,这种打包实现的是预设与其他物件分离,其他物件包括材质球、模型、贴图,材质球中包含着色器和属性信息,贴图往往是一张tga,模型是一个FBX,这样打包羽化认为基本上是最省配置,但要注意加载的时候,在有预设的情况下,最后先下载材质球再下载模型。
[javascript]
&span style="font-size:16"&var download : WWW;
var url = "packed_resource.unity3d";
var resourcePath = "Lerpz";
var guiOffset = 20;
var assetBundle : AssetB
var instanced : O
function StartDownload () {
if (url.IndexOf ("file://") == 0 || url.IndexOf ("http://") == 0)
download = new WWW (url);
else if (Application.platform == RuntimePlatform.OSXWebPlayer || Application.platform == RuntimePlatform.WindowsWebPlayer)
download = new WWW ("../AssetBundles/" + url);
else if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.WindowsEditor)
download = new WWW ("file://" + Application.dataPath + "/../AssetBundles/" + url);
assetBundle = download.assetB
if (assetBundle != null)
var go : Object = assetBundle.mainA
if (go != null)
instanced = Instantiate(go);
Debug.Log("Couldnt load resource");
Debug.Log("Couldnt load resource");
function OnGUI()
GUILayout.Space(guiOffset);
GUILayout.BeginHorizontal();
if (download == null)
if (GUILayout.Button("Download " + url))
StartDownload();
if (download.error == null)
var progress = parseInt(download.progress * 100);
GUILayout.Label(progress + "%");
if (download.isDone && GUILayout.Button("Unload Resource")
Destroy(instanced);
download.Dispose();
download = null;
assetBundle.Unload (true);
assetBundle = null;
GUILayout.Label(download.error);
GUILayout.EndHorizontal();
预设下载和其他下载差不多,只是预设中多了一步实例化。
项目下载地址:(附送“FF13 - 誓言”)
解决方案:
是使用BuildPipeline中的PushAssetDependencies和PopAssetDependencies方法来解决依赖关系.
浏览: 240159 次
来自: 北京
大神,,请问,(isChecked)是什么啊?是bboolea ...
&div class=&quote_title ...
&div class=&quote_title ...
我在设置如何格式化的时候 总是保存不了 不知道楼主有遇到过这种 ...2620人阅读
&&&&&&&& Unity5增加了新的打包AssetBundle方式-& BuildPipeline.,大体思想是把资源以及依赖项分别打包,并用文本记录它们间的依赖关系,这种方式相对旧版本将资源粗暴的打成一个包来说,带来的好处也显而易见,每个资源以及依赖项都只打包一次不会造成依赖循环(不了解的同学可以看一下),但同时打包后的资源更碎片化,导致加载耗时更多。大家都有复制文件的经验,复制一个包比复制一堆碎文件快(同大小的两份文件)同样道理。
&&&&&&& 思想上有点类似李总(李剑英)的资源热更新方案,将资源信息(布局,参数等)解析成文本,使用的时候只需下载文本文件(占用物理内存小),再根据文本文件生成资源。但据我测试,BuildPipeline.执行效率较低,在加载相同prefab的前提下根据文本生成prefab耗时51.59ms,使用BuildPipeline.
加载耗时约118ms。这里只给大家一个大概的参考。
&&&&&& 1.& 打包AssetBundle,代码来源, 稍作修改增加了自动关联依赖项的方法
using UnityE
using System.C
using UnityE
using System.IO;
/// &summary&
/// 把Resource下的资源打包成.data到OutPut目录下
/// &/summary&
public class Builder : Editor
public static string sourcePath = Application.dataPath + &/Resource&;
const string AssetBundlesOutputPath = &Assets/OutPut&;
[MenuItem(&Custom/BuildAssetBundle&)]
public static void BuildAssetBundle()
ClearAssetBundlesName();
Pack(sourcePath);
string outputPath = bine(AssetBundlesOutputPath, Platform.GetPlatformFolder(EditorUserBuildSettings.activeBuildTarget));
if (!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath);
//根据BuildSetting里面所激活的平台进行打包 设置过AssetBundleName的都会进行打包
BuildPipeline.BuildAssetBundles(outputPath, 0, EditorUserBuildSettings.activeBuildTarget);
AssetDatabase.Refresh();
Debug.Log(&打包完成&);
/// &summary&
/// 清除之前设置过的AssetBundleName,避免产生不必要的资源也打包
/// 之前说过,只要设置了AssetBundleName的,都会进行打包,不论在什么目录下
/// &/summary&
static void ClearAssetBundlesName()
int length = AssetDatabase.GetAllAssetBundleNames().L
Debug.Log(length);
string[] oldAssetBundleNames = new string[length];
for (int i = 0; i & i++)
oldAssetBundleNames[i] = AssetDatabase.GetAllAssetBundleNames()[i];
for (int j = 0; j & oldAssetBundleNames.L j++)
AssetDatabase.RemoveAssetBundleName(oldAssetBundleNames[j], true);
length = AssetDatabase.GetAllAssetBundleNames().L
Debug.Log(length);
static void Pack(string source)
//Debug.Log(&Pack source & + source);
DirectoryInfo folder = new DirectoryInfo(source);
FileSystemInfo[] files = folder.GetFileSystemInfos();
int length = files.L
for (int i = 0; i & i++)
if (files[i] is DirectoryInfo)
Pack(files[i].FullName);
if (!files[i].Name.EndsWith(&.meta&))
fileWithDepends(files[i].FullName);
//设置要打包的文件
static void fileWithDepends(string source)
Debug.Log(&file source & + source);
string _source = Replace(source);
string _assetPath = &Assets& + _source.Substring(Application.dataPath.Length);
Debug.Log(_assetPath);
//自动获取依赖项并给其资源设置AssetBundleName
string[] dps = AssetDatabase.GetDependencies(_assetPath);
foreach (var dp in dps)
Debug.Log(&dp & + dp);
if (dp.EndsWith(&.cs&))
AssetImporter assetImporter = AssetImporter.GetAtPath(dp);
string pathTmp = dp.Substring(&Assets&.Length + 1);
string assetName = pathTmp.Substring(pathTmp.IndexOf(&/&) + 1);
assetName = assetName.Replace(Path.GetExtension(assetName), &.data&);
Debug.Log(assetName);
assetImporter.assetBundleName = assetN
//设置要打包的文件
static void file(string source)
Debug.Log(&file source & + source);
string _source = Replace(source);
string _assetPath = &Assets& + _source.Substring(Application.dataPath.Length);
string _assetPath2 = _source.Substring(Application.dataPath.Length + 1);
//Debug.Log (_assetPath);
//在代码中给资源设置AssetBundleName
AssetImporter assetImporter = AssetImporter.GetAtPath(_assetPath);
string[] dps = AssetDatabase.GetDependencies(_assetPath);
foreach (var dp in dps)
Debug.Log(&dp & + dp);
string assetName = _assetPath2.Substring(_assetPath2.IndexOf(&/&) + 1);
assetName = assetName.Replace(Path.GetExtension(assetName), &.unity3d&);
Debug.Log(assetName);
assetImporter.assetBundleName = assetN
static string Replace(string s)
return s.Replace(&\\&, &/&);
public class Platform
public static string GetPlatformFolder(BuildTarget target)
switch (target)
case BuildTarget.Android:
return &Android&;
case BuildTarget.iOS:
return &IOS&;
case BuildTarget.WebPlayer:
return &WebPlayer&;
case BuildTarget.StandaloneWindows:
case BuildTarget.StandaloneWindows64:
return &Windows&;
case BuildTarget.StandaloneOSXIntel:
case BuildTarget.StandaloneOSXIntel64:
case BuildTarget.StandaloneOSXUniversal:
return &OSX&;
2.加载AssetBundle
using UnityE
using System.C
public class TestLoadNewAB : MonoBehaviour
void OnGUI()
if (GUILayout.Button(&LoadAssetbundle&))
DateTime t0 = DateTime.N
//首先加载Manifest文件;
AssetBundle manifestBundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath
+ &/Android/Android&);
Debug.Log(manifestBundle == null);
if (manifestBundle != null)
AssetBundleManifest manifest = (AssetBundleManifest)manifestBundle.LoadAsset(&AssetBundleManifest&);
Debug.Log(manifest == null);
//获取依赖文件列表;
string[] cubedepends = manifest.GetAllDependencies(&cube.data&);
Debug.Log(cubedepends.Length);
foreach (var item in cubedepends)
Debug.Log(&depends & + item);
AssetBundle[] dependsAssetbundle = new AssetBundle[cubedepends.Length];
for (int index = 0; index & cubedepends.L index++)
//加载所有的依赖文件;
dependsAssetbundle[index] = AssetBundle.LoadFromFile(Application.streamingAssetsPath + &/Android/& + cubedepends[index]);
DateTime t1 = DateTime.N
//加载我们需要的文件;&
AssetBundle cubeBundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath + &/Android/cube.data&);
Debug.Log(cubeBundle == null);
GameObject cube = cubeBundle.LoadAsset(&cube&) as GameO
Debug.Log(cube == null);
if (cube != null)
Instantiate(cube);
DateTime t2 = DateTime.N
Debug.Log(&LoadView Time1:& + (t1 - t0).TotalMilliseconds + & Time2:& + (t2 - t1).TotalMilliseconds);//+ & Time3:& + (t3 - t2).TotalMilliseconds
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:3443次
排名:千里之外1051人阅读
unity3d优化(19)
AssetBundle打包(5.x)基础
public static
AssetBundleManifest
BuildAssetBundles(string
outputPath,
BuildAssetBundleOptions
assetBundleOptions = BuildAssetBundleOptions.None,
BuildTarget
targetPlatform = BuildTarget.WebPlayer);
调用BuildPipeline.BuildAssetBundles,引擎将自动根据资源的assetbundleName属性(以下简称abName)批量打包,自动建立Bundle以及资源之间的依赖关系。
在资源的Inpector界面最下方可设置一个abName,每个abName(包含路径)对应一个Bundle,即abName相同的资源会打在一个Bundle中。如果所依赖的资源设置了不同的abName,则会与之建立依赖关系,避免出现冗余。
支持增量式发布,即在资源内容改变并重新打包时,会自动跳过内容未变的Bundle。因此,相比4.x,会极大地缩短更新Bundle的时间。
&新打包选项除了前文提到的,5.x下默认开启的三个选项(CompleteAssets ,用于保证资源的完备性;CollectDependencies,用于收集资源的依赖项;DeterministicAssetBundle,用于为资源维护固定ID)之外,5.x中新增了以下选项:
●&ForceRebuildAssetBundle,用于强制重打所有AssetBundle文件;
●&IgnoreTypeTreeChanges,用于判断AssetBundle更新时,是否忽略TypeTree的变化;
●&AppendHashToAssetBundleName,用于将Hash值添加在AssetBundle文件名之后,开启这个选项,可以直接通过文件名来判断哪些Bundle的内容进行了更新(4.x下普遍需要通过比较二进制等方法来判断,但在某些情况下即使内容不变重新打包,Bundle的二进制也会变化)。
与4.x不同的是,对于移动平台,5.x下默认会将TypeTree信息写入AssetBundle,因此在移动平台上DisableWriteTypeTree选项也变得有意义了。
&Manifest文件在4.x版本中,我们通常需要自行维护配置文件,以记录AssetBundle之间的依赖关系,并供运行时使用。而在5.x版本中,Manifest文件可以免去这一过程。&Variant参数Variant参数能够让AssetBundle方便地进行“多分辨率支持”,相关详解请移步下文。
AssetBundle
打包(5.x)进阶
在新系统中,添加了以下两个实用的新特性,也许能够给开发者带来事半功倍的效果。Manifest文件在打包后生成的文件夹中,每个Bundle都会对应一个manifest文件,记录了Bundle的一些信息,但这类manifest只在增量式打包时才用到;同时,根目录下还会生成一个同名manifest文件及其对应的Bundle文件,通过该Bundle可以在运行时得到一个AssetbundleManifest对象,而所有的Bundle以及各自依赖的Bundle都可以通过该对象提供的接口进行获取。&Variant参数在资源的Inspector界面最下方,除了可以指定abName,在其后方还可以指定Variant。打包时,Variant会作为后缀添加在Bundle名字之后。相同abName,不同variant的Bundle中,资源必须是一一对应的,且他们在Bundle中的ID也是相同的,从而可以起到相互替换的作用。
当需要为手机和平板上的某个UI界面使用两套分辨率不同的纹理、Shader,以及文字提示时,借助Variant的特性,只需创建两个文件夹,分别放置两套不同的资源,且资源名一一对应,然后给两个文件夹设置相同的abName和不同的variant,再给UI界面设置abName,然后进行打包即可。运行时,先选择合适的依赖包加载,那么后续加载UI界面时,会根据已加载的依赖包,呈现出相对应的版本。
开发者注意事项
●&abName可通过脚本进行设置和清除,也可以通过构造一个AssetBundleBuild数组来打包。
新机制打包无法指定Assetbundle.mainAsset,因此无法再通过mainAsset来直接获取资源。
开启DisableWriteTypeTree可能造成AssetBundle对Unity版本的兼容问题,但会使Bundle更小,同时也会略微提高加载速度。
●&Prefab之间不会建立依赖,即如果Prefab-A和Prefab-B引用了同一张纹理,而他们设置了不同的abName,而共享的纹理并未设置abName,那么Prefab-A和Prefab-B可视为分别打包,各自Bundle中都包含共享的纹理。因此在使用UGUI,开启Sprite
Packer时,由于Atlas无法标记abName,在设置UI界面Prefab的abName时就需要注意这个问题。
●&5.x中加入了Shader
stripping功能,在打包时,默认情况下会根据当前场景的Lightmap及Fog设置对资源中的Shader进行代码剥离。这意味着,如果在一个空场景下进行打包,则Bundle中的Shader会失去对Lightmap和Fog的支持,从而出现运行时Lightmap和Fog丢失的情况.而通过将Edit-&Project Settings-&Graphics下shader Stripping中的modes改为Manual,并勾选相应的mode即可避免这一问题。
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:128064次
积分:1822
积分:1822
排名:千里之外
原创:43篇
转载:67篇
评论:21条
(13)(7)(1)(7)(5)(3)(3)(1)(1)(14)(17)(18)(10)(7)(1)(2)89951人阅读
unity(12)
在手游的运营过程中,更新资源是比不可少的。资源管理第一步是资源打包。传统的打包可以将所有物件制成预设Prefab,打包成场景。今天我们来一起学习官方推荐的Assetbundle,它是Unity(Pro)提供的资源打包策略。利用AssetBundle,可以将几乎所有的资源都打包封装,便于客户端更新下载新的资源。
(转载请注明原文出处)
创建AssetBundle
1.创建一个空的Prefab,命名Cube,然后创建一个Cube,将其拉到刚创建好的Prefab
2.新建一个脚本ExportAssetBundles.cs(代码来自官方文档),保存在Asset/Editor目录下
//在Unity编辑器中添加菜单
[MenuItem(&Assets/Build AssetBundle From Selection&)]
static void ExportResourceRGB2()
// 打开保存面板,获得用户选择的路径
string path = EditorUtility.SaveFilePanel(&Save Resource&, &&, &New Resource&, &assetbundle&);
if (path.Length != 0)
// 选择的要保存的对象
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | pleteAssets, BuildTarget.StandaloneWindows);
}这时我们将看到Asset下面出现Build AssetBundle From Selection和Build Scene
3.选中预设Cube,运行Build AssetBundle From Selection。这时会弹出一个保存框,将其命名为cube.unity3d(这里为了测试方便,放在c盘。实际项目中,我们是需要将他们放在web服务器,供所有客户端下载更新)
4.新建一个场景scene1.unity,上面放置几个模型,然后保存
5.选中该场景,在之前的ExportAssetBundles.cs脚本中添加打包场景的函数,运行Assets-&Build Scene,保存为scene1.unity3d(这里为了测试方便,也放在c盘)
[MenuItem(&Assets/Save Scene&)]
static void ExportScene()
// 打开保存面板,获得用户选择的路径
string path = EditorUtility.SaveFilePanel(&Save Resource&, &&, &New Resource&, &unity3d&);
if (path.Length != 0)
// 选择的要保存的对象
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
string[] scenes = {&Assets/scene1.unity&};
BuildPipeline.BuildPlayer(scenes,path,BuildTarget.StandaloneWindows,BuildOptions.BuildAdditionalStreamedScenes);
a.AssetBundle的保存后缀名可以是assetbundle或者unity3d
b.BuildAssetBundle要根据不同的平台单独打包,BuildTarget参数指定平台,如果不指定,默认的webplayer
加载AssetBundle
我们通过一个简单的代码来演示如何加载assetbundle,包括加载普通asset和场景。
using UnityE
using System.C
public class Load: MonoBehaviour
private string BundleURL = &file:///C:/cube.assetbundle&;
private string SceneURL = &file:///C:/scene1.unity3d&;
void Start()
//BundleURL = &file//&+Application.dataPath+&/cube.assetbundle&;
Debug.Log(BundleURL);
StartCoroutine(DownloadAssetAndScene());
IEnumerator DownloadAssetAndScene()
//下载assetbundle,加载Cube
using (WWW asset = new WWW(BundleURL))
AssetBundle bundle = asset.assetB
Instantiate(bundle.Load(&Cube&));
bundle.Unload(false);
yield return new WaitForSeconds(5);
//下载场景,加载场景
using (WWW scene = new WWW(SceneURL))
AssetBundle bundle = scene.assetB
Application.LoadLevel(&scene1&);
a.LoadFromCacheOrDownload 可以指定版本,如果本地版本是新的,将不会从服务器读取
b.如果是多个资源打包在一起,我们要通过bundle.Load(),加载特定的资源
c.挂载在模型上的脚本也可以一起打包,但是保证脚本在原目录也要存在,否则加载出来无法运行。关于如何更新脚本,我将放在以后的章节中阐述。
AssetBundle依赖关系
如果一个公共对象被多个对象依赖,我们打包的时候,可以有两种选取。一种是比较省事的,就是将这个公共对象打包到每个对象中。这样会有很多弊端:内存被浪费了;加入公共对象改变了,每个依赖对象都得重新打包。AssetBundle提供了依赖关系打包。我们通过一个简单的例子来学习
//启用交叉引用,用于所有跟随的资源包文件,直到我们调用PopAssetDependencies
BuildPipeline.PushAssetDependencies();
var options =
BuildAssetBundleOptions.CollectDependencies |
//所有后续资源将共享这一资源包中的内容,由你来确保共享的资源包是否在其他资源载入之前载入
BuildPipeline.BuildAssetBundle(
AssetDatabase.LoadMainAssetAtPath(&assets/artwork/lerpzuv.tif&),
null, &Shared.unity3d&, options);
//这个文件将共享这些资源,但是后续的资源包将无法继续共享它
BuildPipeline.PushAssetDependencies();
BuildPipeline.BuildAssetBundle(
AssetDatabase.LoadMainAssetAtPath(&Assets/Artwork/Lerpz.fbx&),
null, &Lerpz.unity3d&, options);
BuildPipeline.PopAssetDependencies();
这个文件将共享这些资源,但是后续的资源包将无法继续共享它
BuildPipeline.PushAssetDependencies();
BuildPipeline.BuildAssetBundle(
AssetDatabase.LoadMainAssetAtPath(&Assets/Artwork/explosive guitex.prefab&),
null, &explosive.unity3d&, options);
BuildPipeline.PopAssetDependencies();
BuildPipeline.PopAssetDependencies();我们在程序加载的时候必须保证先加载公共对象。否则,只能是在各个对象加载成功后,再通过程序手动添加进来,比较繁琐。在实际项目中,由于是团队开发,对象间的依赖关系通常会比较凌乱,最好在开发周期就定好相关的规范约束,方便管理。
这一节的内容偏实际操作,官方文档和雨松的blog中已经有更加详细介绍。如果大家还有不明白的地方,可以结合文档再实际操作一下。后面的章节,我将花更多的时间介绍核心的内容:资源的增量更新,和代码程序的更新。
/s/1i3BOAPn
2./Manual/DownloadingAssetBundles.html
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:490544次
积分:2764
积分:2764
排名:千里之外
原创:14篇
评论:145条
有任何问题欢迎交流
(1)(1)(11)(1)}

我要回帖

更多关于 buildassetbundles 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信