Unity5.x 怎样在打包时候设置mainmirae asset 上海

关于采用Unity 5.x 提供的增量式打包单个模型后AssetBundle doesn’t have main asset解决方法
1.可通过AssetBundle.LoadAllAssetsAsync()后使用AssetBundleRequest.asset 代替原有AssetBundle.mainAsset,代码如下
public class ExmpDownloadAssetBundleForNew : MonoBehaviour
IEnumerator Start ()
string url = "http://.........";
WWW www = new WWW(url);
yield return
if (www.isDone && string.IsNullOrEmpty(www.error))
AssetBundle ab = www.assetB
AssetBundleRequest abr =
ab.LoadAllAssetsAsync&GameObject&();
yield return
if (abr != null)
CallBack(url, abr.asset);
if (www.assetBundle) www.assetBundle.Unload(false);
www.Dispose();
public void CallBack(string url, UnityEngine.Object ob)
///相关处理操作
2.可通过AssetBundle.LoadAllAssets()[0],因为就打包一个模型,所以加载所有的Assets,取第0个就是它自己了。相关代码,参考1即可。
以上2种使用,希望能帮助一些有疑问的朋友,如有问题请不吝指正!
没有更多推荐了,Unity5.x 怎样在打包时候设置mainasset_百度知道
Unity5.x 怎样在打包时候设置mainasset
我有更好的答案
这个没设置项
采纳率:70%
来自团队:
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。No AssetBundle.mainAsset with BuildingAssetBundles in 5.x ? - Unity Answers
Navigation
Unity account
You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio.
No AssetBundle.mainAsset with BuildingAssetBundles in 5.x ?
In Unity 4.x we used
to build an AssetBundle. The first parameter was the mainAsset:
mainAsset Lets you specify a specific object that can be conveniently retrieved using AssetBundle.mainAsset.
But as BuildAssetBundle is now marked obsolete we use
in Unity 5.x. But this function has no parameter mainAsset. And I can't find a &Set main asset& option in the AssetBundle authoring tools either.
Question: Is there another way to set the mainAsset parameter for each AssetBundle in Unity 5.x?
public static object getMainAsset(AssetBundle assetBundle){ return assetBundle.LoadAsset(assetBundle.GetAllAssetNames()[0]); }
I have the same problem! Now I do a mapping for mainAsset.
Hint: You can notify a user about this post by typing @username
Attachments: Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
5 People are following this question.搜索结果部分由温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
我是阿赵,请多多指教!
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
http://liweizhaolili.blog.163.com/blog/static// 先来说说关于旧版本的AssetBundle的事情。 之前我写了一个批量导出AssetBundle的小插件,有朋友留言说我没有解决依赖关系。后来在一位同事的指导下,我终于把这个问题搞清楚了,其实说白了过程就是先扫描所有要打包的资源,然后用AssetDatabase.GetDependencies获得所有的依赖,自己记录起来,由于怕资源之间有重名的,所以最好用AssetDatabase.AssetPathToGUID获得资源的唯一id,然后存起来。获得了所有依赖关系之后,再使用BuildPipeline.PushAssetDependencies和BuildPipeline.PopAssetDependencies按照层级和顺序来打包。这样打出来的资源就完全的保留了依赖关系,文件也拆得很散很小,不会重复打包了。 在加载的时候,由于我们是预先记录了各个资源的依赖关系,所以在加载某一个资源的时候,先去保存的文件里面查找它的依赖关系,把所有用到的依赖资源都先加载一次,然后再加载它,就能完整的加载出一个想要的模型之类了。 这就是完整的旧版本AssetBundle依赖打包和加载的流程了。不过由于是受人指导学会的,所以不方便把全部代码贴出来。 再来看看5.0版本的心AssetBundle的使用情况: 看到新版本的AssetBundle,我那位同事估计会一口老血喷在屏幕上面。那是因为,这个辛辛苦苦做出来的打包策略,Unity已经集成了。 新版本的AssetBundle在打包的时候多了一个叫做BuildPipeline.BuildAssetBundles(outputPath)的方法,然后每一个资源可以设置一个assetBundleName。只要你调用这个方法,那么所有已经设置过assetBundleName的资源,就会自动打包,具体的好处有:1、可以直接在编辑器UI上设置操作2、提供了更简便的脚本API3、Unity本身会处理所有的依赖关系4、生成了一种叫做manifest的文件,用于记录资源之间的依赖关系,并以链式结构记录,修改时只需修改链的其中一环5、增量打包功能。以上的好处,是官方说明的,我大概操作了一下,说的都是事实,只是使用时有点需要注意的地方。 很明显的看出,这些优点,正是我那位同事已经做过的事情,和一些暂时没有做到的事情。 先来说说最多人关心的问题,Unity自己处理依赖关系。 实际上来说,所有需要打包成AssetBundle的资源,你是要先赋予它一个assetBundleName的,在它有了assetBundleName之后,实际上它的信息已经存在于AssetDataBase里面了。所以在打包的时候,只需要调用BuildPipeline.BuildAssetBundles方法,它会把记录了的在AssetDataBase里面的所有资源先计算出依赖关系,再拆分打包。这个步骤是一点问题都没有的。要注意的是,你所有依赖的资源都必须赋予assetBundleName,不然,依赖就不会被拆分。 在加载的时候,AssetBundle的特性是和旧版本一样的,就是当一个目标资源的依赖资源已经存在与内存中(也就是已经被加载过了),那么在加载目标资源的时候,Unity会自动的帮你找到依赖关系。所以在加载的时候实际上还是要你手动加载依赖资源的。这一点和旧版本一样。 再来说说打包工具的编写。 虽然官方说得很美好,一句BuildPipeline.BuildAssetBundles(outputPath)就可以直接把所有资源都打包了,而需要打包的资源可以在编辑器界面直接输入。但实际上由于上面说到的必须赋予每一个依赖资源assetBundleName,你不可能每一个资源去手动的查找用到的依赖资源再在编辑器输入名字,所以旧版本的打包流程还是要的。 首先,你可以遍历需要打包的文件夹,把所有需要打包的预设或者资源都找到,然后设置assetBundleName,然后,通过AssetDatabase.GetDependencies方法逐个找到资源的依赖资源路径,用AssetDatabase.AssetPathToGUID算出每个资源的唯一ID,然后将唯一ID当做assetBundleName赋予给每个依赖资源。最后,调用BuildPipeline.BuildAssetBundles(outputPath)打包到指定位置。 最后说说加载。 由于依赖关系都存在于manifest中,所以在加载资源之前,要先加载manifest文件。 实际上在打包的时候,会有一个总的manifest文件,叫做AssetBundle.manifest,然后每一个小的资源分别有一个自己的manifest文件。在我们加载的时候,需要先把总的AssetBundle加载进来。比如这样:& & & & string mUrl = Cdn + "AssetBundle";& & & & WWW mwww = WWW.LoadFromCacheOrDownload(mUrl, 0);& & & && & & & if (!string.IsNullOrEmpty(mwww.error))& & & & {& & & & & & Debug.Log(mwww.error);& & & & }& & & & else& & & & {& & & & & & AssetBundle mab = mwww.assetB& & & & & & AssetBundleManifest mainfest = (AssetBundleManifest)mab.LoadAsset("AssetBundleManifest");& & & & & & mab.Unload(false);其中Cdn是我的资源路径,加载完之后,得到了一个AssetBundleManifest&对象。然后根据我们需要加载的资源名称,获得所有依赖资源:& & & & & & string[] dps = mainfest.GetAllDependencies(realName);& & & & & & AssetBundle[] abs = new AssetBundle[dps.Length];& & & & & & for (int i = 0; i & dps.L i++)& & & & & & {& & & & & & & & string dUrl = Cdn + dps[i];& & & & & & & & WWW dwww = WWW.LoadFromCacheOrDownload(dUrl, mainfest.GetAssetBundleHash(dps[i]));& & & & & & & && & & & & & & & abs[i] = dwww.assetB& & & & & & }其中realName是想加载的AssetBundle的名字,需要带扩展名。通过了这一步,所有的依赖资源都加载完了,可以加载目标资源了:&WWW www = WWW.LoadFromCacheOrDownload(url, mainfest.GetAssetBundleHash(realName+".ab"), 0);& & & & & && & & & & & if (!string.IsNullOrEmpty(www.error))& & & & & & {& & & & & & & & Debug.Log(www.error);& & & & & & }& & & & & & else& & & & & & {& & & & & & & & AssetBundle ab = www.assetB& & & & & & & & GameObject gobj = ab.LoadAsset(realName) as GameO& & & & & & & & if (gobj != null)& & & & & & & & & & Instantiate(gobj);& & & & & & & & ab.Unload(false);& & & & & & }& & & & & & foreach (AssetBundle ab in abs)& & & & & & {& & & & & & & & ab.Unload(false);& & & & & & }到这一步,所有的资源都加载完毕了。注意的是,记得Unload,不然下次就加不进来了。或者不Unload的话,就做一个字典记录所有加载过的AssetBundle,还有它们的引用计数器。那样就可以先判断是否存在在加载。
以上就是Unity5.0的AssetBundle的使用方法了。下面来吐槽一下。1、看Unite2014大会的视频介绍时,感觉这个东西真好,提供了这么强大的功能和这么简单的API。但实际用过之后,发现整个打包和加载的过程其实和旧版差不多,真正有意义的功能,是manifest的链式结构,和增量打包功能。2、我在没有使用之前,以为可以按照文件夹结构来打包,那样的话,就可以简单的从Resources.Load和外部WWW加载中做切换,只需要替换一个CDN地址就可以了。但实际上Unity把所有AssetBundle都打包在了同一个目录,在这个转换的过程中,我们还需要记录一下两者的对应关系。(其实这一点是错误的,assetName只要是带“/”的,就能自动生成文件夹结构的,之后的文章都忘记提了,误导了大家)3、资源打包的策略有时候和项目的设计本身有关,如果是阶段性很明确的资源管理,可能旧版的AssetBundle打包也不错。4、现在只看了Unity5的AssetBundle觉得不错,但又看了一下其他功能,发现Unity5的很多功能都改了,这样的大改动对于旧项目来说有可能是影响非常大的,是不是值得为了新的AssetBundle而升级Unity,还是需要更多的评估。
阅读(57494)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'Unity5的AssetBundle的一点使用心得',
blogAbstract:'\t昨天一位朋友在我这里留言,想让我写点Unity5的AssetBundle心得。于是我就看了相关的介绍,和自己确切的做了一次。下面来谈谈所谓的心得。\t如果你觉得自己对AssetBundle不熟悉,建议先看看另外一篇文章:http://liweizhaolili.blog.163.com/blog/static//\t先来说说关于旧版本的AssetBundle的事情。',
blogTag:'unity5,assetbundle',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:7,
publishTime:8,
permalink:'blog/static/',
commentCount:116,
mainCommentCount:31,
recommendCount:2,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'我是阿赵,请多多指教!',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}}

我要回帖

更多关于 exp asset咨询战神老师 的文章

更多推荐

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

点击添加站长微信