为什么unity3d怎么打开通过bulid后,打开bulid的出来应用的时候缺少一部分

阅读:14564回复:39
Metaio in Unity3d 教程--- 一. 搭建环境,运行官方案例
发布于: 17:48
Metaio in Unity3d 教程--- 一. 搭建环境,运行官方案例
本文以Metaio SDK 5.3作为案例讲解。
第一步:上官网下载SDK安装包:,并安装。
这个安装包就是SDK包,包含了Android\ios\windows\unity3d的sdk。
726 || this.offsetHeight>700){if(this.offsetWidth/726 > this.offsetHeight/700){this.width=726;}else{this.height=700;}}" style="max-width:726max-height:700" title="点击查看原图" onclick="if(this.parentNode.tagName!='A') window.open('/forum/attachment/1403/thread/27_.jpg');" />
桌面unity3d快捷方式右键属性,将unity3d设置为强制使用opengl打开,即在目标中加入 &-force-opengl
如果电脑中有摄像头,就可以直接在editor模式下扫描了。
第二步:打开官方案例
打开unity3d,找到官方案例的工程目录:...\metaio SDK\SDK_Unity\Example
726 || this.offsetHeight>700){if(this.offsetWidth/726 > this.offsetHeight/700){this.width=726;}else{this.height=700;}}" style="max-width:726max-height:700" title="点击查看原图" onclick="if(this.parentNode.tagName!='A') window.open('/forum/attachment/1403/thread/27_f2307683da.png');" />
Project 面板中的目录。
Plugins包含了Android、iOS的插件。
StreamAssets是一个重要的文件夹,把扫描相关的文件都放在这里。
第三步:学习HelloWorld案例
我们来看第一个教程。打开Tutorial1中的场景文件。
726 || this.offsetHeight>700){if(this.offsetWidth/726 > this.offsetHeight/700){this.width=726;}else{this.height=700;}}" style="max-width:726max-height:700" title="点击查看原图" onclick="if(this.parentNode.tagName!='A') window.open('/forum/attachment/1403/thread/27_a2f0efacac.png');" />
(1)在Hierarchy面板中,metaioSDK物体上贴有metaioSDK.cs文件。
其中SDK Signature是metaio的签名,需要到官网上申请一个,要与项目的Bundle Identifier相对应。
比如官方案例的
Bundle Identifer是:com.metaio.unity.Example
SDK Signature是: & fSA5ZtAybUBiXenYXDByoDHQXL/g0p0Wy7PJx5xHY7A=
这个是保证版权的部分,两者需要相对应才可以运行,需要到官网上去申请,如果是购买了SDK,就不会有水印,没有购买也可以申请,但会有水印。具体的操作方法在下一篇文章中介绍。
Camera index是摄像头的编号,在手机中,0表示后置摄像头,1表示前置摄像头。
Camera width\height是分辨率,分别有320*240、640*480、,也可以自己定义。分辨率越高,显像越清晰,当然也就越卡了。
Select configuration中有几种模式,选择StreamingAssets,下面的tracking文件是tracking相关的参数文件,必须存在StreamingAssets文件夹下。
(2)DevieceCamera是获得摄像头的信息,然后投影到CameraPlane上,所以你看到的Scene面板中的CameraPlane是紫色的,因为没有给它赋予材质。
MainCamera是用来看场景。
(3)metaioTracker是扫描结果,它的子物体是扫描出来的结果。扫描出来的时候会显示所有子物体,没有扫描出来的时候会隐藏所有子物体。
726 || this.offsetHeight>700){if(this.offsetWidth/726 > this.offsetHeight/700){this.width=726;}else{this.height=700;}}" style="max-width:726max-height:700" title="点击查看原图" onclick="if(this.parentNode.tagName!='A') window.open('/forum/attachment/1403/thread/27_44528b4c.png');" />
metaioTracker上贴的脚本是metaioTracker.cs,其中的Coordinate Sytem ID 是扫描的编号,与tracking.xml中相对应,后面会继续讲到。
第四步:导出apk,运行在android平台上
726 || this.offsetHeight>700){if(this.offsetWidth/726 > this.offsetHeight/700){this.width=726;}else{this.height=700;}}" style="max-width:726max-height:700" title="点击查看原图" onclick="if(this.parentNode.tagName!='A') window.open('/forum/attachment/1403/thread/27_e8da330f26.png');" />
需要有android SDK。
File -&Build Setting &先Switch Platform,然后Build And Run.
第五步:导出ios平台运行。
需要有ios SDK。
File -&Build Setting &先Switch Platform,然后Build And Run.
导出xcode工程,
726 || this.offsetHeight>700){if(this.offsetWidth/726 > this.offsetHeight/700){this.width=726;}else{this.height=700;}}" style="max-width:726max-height:700" title="点击查看原图" onclick="if(this.parentNode.tagName!='A') window.open('/forum/attachment/1403/thread/27_2026_77aae937f22dc07.jpg');" />
需要增加三个library,
.../Libraries/metaiosdk(Add Other...)
libxml2.dylib
Security.framework
libc++.dylib
sdk5.5需要增加一个library: CoreImage.framework (SDK 5.5 and newer)
第六步:导出exe版本
打开之后出现白屏,且提示要用-force -opengl打开
726 || this.offsetHeight>700){if(this.offsetWidth/726 > this.offsetHeight/700){this.width=726;}else{this.height=700;}}" style="max-width:726max-height:700" title="点击查看原图" onclick="if(this.parentNode.tagName!='A') window.open('/forum/attachment/1407/thread/27_2026_e2fcf10361c4aaa.png');" />
不要的担心,增加一个快捷方式,在快捷方式中加 -force -opengl,然后打开这个快捷方式,就可以了。类似第一步。
那么这个appKeys.xml是干嘛用的呢?
&Keys&
&&AppID&&/AppID&
&&SignatureKey&&/SignatureKey&
&/Keys&
没错,就是sdk signature,需要你自己再填一下。每次导出都会有新的AppID,建议最后一次发布的时候再申请
另外有可能遇到windows7 8 和x86 x64的问题,这个大家多折磨几次就明白了
以上为本人学习所得,欢迎讨论,共同进步。教程只会在圣典更新发布,其他转载请注明来源
官方教程:
官方视频教程:
当然都是youtube上的。
&
欢迎到qq群中讨论,非官方群:本部分内容设定了隐藏,需要回复后才能看到
敬请期待 & Metaio in Unity3d 教程
一. 搭建环境,运行官方案例 & & & & & & & & & & &/forum/read.php?tid=16268
二. 创建自己的Application & & & & & & & & & & & &
三. 使用ID Marker作为扫描目标 & & & & & & & &
四:再谈谈图片扫描之tracking配置文件 &
[明一于 09:58编辑了帖子]
共1条评分,
最新喜欢:
鲜花2991朵
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 08:45
支持不错继续
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 10:27
支持,期待你的所有篇!!~~~
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 18:32
这个插件干吗用的呢?
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 17:53
:这个插件干吗用的呢? AR
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 18:36
很好用的插件,支持!!!
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 20:52
正在学习,感谢群主
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 14:16
如果发布成pc版的要怎么设置啊?直接发布就好嘛?
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 11:14
强制用opengl & 那里我的电脑说是路径错误什么的。没有办法设置啊
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 14:22
:强制用opengl & 那里我的电脑说是路径错误什么的。没有办法设置啊 如果你不再pc上调试,那不用设置也可以的
您需要登录后才可以回帖,&或者&
Powered by用Unity和Android交互出现一个问题,请大家看看_unity3d吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:24,631贴子:
用Unity和Android交互出现一个问题,请大家看看收藏
用Eclipse写了一个Android程序,导出jar文件,然后放在Unity里。生成APK文件的时候出现了下面的错误,求大神帮忙看一下。。Error building Player: CommandInvokationFailure: Failed to re-package resources. See the Console for details.F:\adt-bundle-windows-x86-\sdk\build-tools\android-4.4W\aapt.exe package --auto-add-overlay -v -f -m -J gen -M AndroidManifest.xml -S "res" -I "F:/adt-bundle-windows-x86-/sdk/platforms/android-20\android.jar" -F bin/resources.ap_stderr[res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.]stdout[Configurations: (default) v11 v14 hdpi mdpi xhdpi xxhdpiFiles:
drawable\app_icon.png
Src: () res\drawable\app_icon.png
drawable\ic_launcher.png
Src: (hdpi) res\drawable-hdpi\ic_launcher.png
Src: (mdpi) res\drawable-mdpi\ic_launcher.png
Src: (xhdpi) res\drawable-xhdpi\ic_launcher.png
Src: (xxhdpi) res\drawable-xxhdpi\ic_launcher.png
layout\main.xml
Src: () res\layout\main.xml
values\strings.xml
Src: () res\values\strings.xml
values\styles.xml
Src: () res\values\styles.xml
Src: (v11) res\values-v11\styles.xml
Src: (v14) res\values-v14\styles.xml
AndroidManifest.xml
Src: () AndroidManifest.xmlResource Dirs:
Type drawable
drawable\app_icon.png
Src: () res\drawable\app_icon.png
drawable\ic_launcher.png
Src: (hdpi) res\drawable-hdpi\ic_launcher.png
Src: (mdpi) res\drawable-mdpi\ic_launcher.png
Src: (xhdpi) res\drawable-xhdpi\ic_launcher.png
Src: (xxhdpi) res\drawable-xxhdpi\ic_launcher.png
Type layout
layout\main.xml
Src: () res\layout\main.xml
Type values
values\strings.xml
Src: () res\values\strings.xml
values\styles.xml
Src: () res\values\styles.xml
Src: (v11) res\values-v11\styles.xml
Src: (v14) res\values-v14\styles.xmlIncluding resources from package: F:\adt-bundle-windows-x86-\sdk\platforms\android-20\android.jarapplyFileOverlay for drawableapplyFileOverlay for layoutapplyFileOverlay for animapplyFileOverlay for animatorapplyFileOverlay for interpolatorapplyFileOverlay for transitionapplyFileOverlay for xmlapplyFileOverlay for rawapplyFileOverlay for colorapplyFileOverlay for menuapplyFileOverlay for mipmapProcessing image: res\drawable\app_icon.pngProcessing image: res\drawable-hdpi\ic_launcher.pngProcessing image: res\drawable-mdpi\ic_launcher.png
(processed image res\drawable-mdpi\ic_launcher.png: 82% size of source)Processing image: res\drawable-xhdpi\ic_launcher.png
(processed image res\drawable-hdpi\ic_launcher.png: 77% size of source)Processing image: res\drawable-xxhdpi\ic_launcher.png
(processed image res\drawable-xhdpi\ic_launcher.png: 74% size of source)
(processed image res\drawable\app_icon.png: 94% size of source)
(processed image res\drawable-xxhdpi\ic_launcher.png: 72% size of source)
(new resource id app_icon from drawable\app_icon.png #generated)
(new resource id ic_launcher from hdpi\drawable\ic_launcher.png #generated)
(new resource id ic_launcher from mdpi\drawable\ic_launcher.png #generated)
(new resource id ic_launcher from xhdpi\drawable\ic_launcher.png #generated)
(new resource id ic_launcher from xxhdpi\drawable\ic_launcher.png #generated)
(new resource id main from res\layout\main.xml)]在用Eclipse创建Android项目的时候,如果把Minimum Required SDK选择为Android4.0或以上,则不会报错。否则就会报上面的错误。
因为4.0以上自带Theme.AppCompat主题 4.0以前版本要使用还得自己添加jar包
1.首先要下载Support Library,你可以在Eclipse中打开SDK Manager中下载,如下图下载完成后你会在你的sdk安装目录中找到jar包,如楼主sdk的安装路径为E:\Android_SDK\extras\android\support\v7\appcompat\libs可以找到android-support-v7-appcompat.jar路径为&sdk&\extras\android\support/v7\appcompat\libs\android-support-v7-appcompat.jar。&sdk&为你的实际SDK安装路径2.添加v7 appcompat 库,具体分步骤见下:2.1 在你的工程的根目录建立一个文件夹叫libs2.2 将android-support-v7-appcompat.jar复制到上面建立的文件夹libs中2.3 右击android-support-v7-appcompat.jar文件,选择Build Path & Add to Build Path.如下图:
我也出现这个问题了。。。好悲催。
AndroidManifest.xml
这个XML文件有问题!
我也遇到这个问题了。。。。
这问题…………2楼大神已解
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或当前位置: >
> 编译未报错 点击Bulid后就报错:应用程序无法正常启动0xc000007b,该如何处理
编译未报错 点击Bulid后就报错:应用程序无法正常启动0xc000007b,该如何处理
useryee & at
编译未报错 点击Bulid后就报错:应用程序无法正常启动0xc000007b最近在搞Matlab和VC++联合编程,电脑是WIN7&64位&+&Matlab2010&+&VC6.0
VC++目录中指定了库文件和包含文件位置,附加依赖项也添加了相应的lib文件,环境变量也设置了。代码如下:
  #include&&stdio.h&
#include&"engine.h"
void&main()
int&status=0;
ep=engOpen(NULL);
if&(ep==(Engine&*)NULL)
printf("Error:&Cant&Open!\n");
engEvalString(ep,"mesh(peaks);");
getchar();
status=engClose(ep);
if&(status!=0)
printf("error:&cant&Close!\n");
编译未报错&点击Build后就报错:应用程序无法正常启动0xc000007b
最开始以为是VC6.0对WIN7&64位兼容不好,故换成了VS2008,结果出现同样问题。。。依然不甘心,用VS2010试试,结果还是出现同样问题.代码应该没问题,照着书上敲的。请教问题出在哪里啊?难道是64位系统的毛病?
引用:  编译未报错&点击Build后就报错:应用程序无法正常启动0xc000007b
点Build报这种错?不是点运行报错?userzc & &
& & (0)(0)引用:  matlab&64位&工程32位吧,最开始用64位lib文件提示无法打开,然后从朋友那里考了个32位matlab的lib文件,编译通过了,但是一点击感叹号就出错。
那么工程也必须是64位的
\MATLAB\xxxxx\extern\lib\win64\microsoftusetemp & &
& & (0)(0)
本问题标题:
本问题地址:
温馨提示:本问题已经关闭,不能解答。
暂无合适的专家
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&&&湘教QS2-164&&增值电信业务经营许可证湘B2-ma_haile 的BLOG
用户名:ma_haile
文章数:38
评论数:23
访问量:393877
注册日期:
阅读量:48278
阅读量:2561
[匿名]51cto游客:
51CTO推荐博文
& 首先先去Unity3D官网 /,我们可以看到很多关于Unity3D的消息。点击DownLoad开始下载Unity,下载的时候建议不要使用 建议是迅雷下载&
unity 并不是免费版的哦 &各位同学 安装完成后需要注册 但作为 比较火的u3d 来说 当然是有破解版的啦, unity 收费模式和大家平常见得软件收费模式是有点不同的哦
unity 是 按功能模块收费的 意思是 发布不同的 平台下的的游戏 需要购买不同的激活码 ,如果是个人学习研究的话,嘿嘿 我们就没必要去购买了, 但如果是公司还是去购买一个吧,不然会 出现版权问题的哦 &下图我们看下unity 的 模块价格
单位是美金哦 ,咔咔 &真贵,,嘿 &但对于游戏公司来说 不算什么啦 &
上图中出现了 pro 版本 而且价格比普通的贵了3倍 多 &pro 版本的意思是专业增强版 & &具体功能有什么不同 大家去官网 去看看 &
启动unity (未注册过的情况下)
点击register 进入下一步
选择 internet activation 激活 并下一步 会连接unity 服务器 并打开unity官网
&输入邮箱和 公司名称 &在这里 点击 free 可以获取30 天的试用版 串号 &点击start pro/ios trial & 开始激活 获取激活串号&&拿到激活串号&&在下面 填入 并点击&Activate Unity 即可 &
即完成了激活流程 &
这里给各位童鞋 提供一个破解包(见附件) 方便大家学习 &激活方法 把激活文件覆盖到unity 的安装目录 &&安装盘&\Program Files\Unity\Editor\ 下面 &记得要覆盖哦 否则可能破解不成功
然后启动unity 点击注册后 选择 maunal activation&
点击read License 然后选择刚刚考到安装目录下的 破解文件 并点击 激活 即可完成破解啦 呵呵 &
好了 ,我们现在重新启动unity&
首先 映入眼帘的是u3d自带的一个demo & &由于我们本章的目标是 发布unity android 游戏 所以本章节 就不多介绍unity的各个功能点介绍了 ,后续会慢慢介绍 讲解
现在我们就拿这儿demo 来发布一款android 游戏
点击File -》 build seting&
因为我们要发布android 平台下的 &选择android平台 点击player settings&
更改一些游戏部署信息 这里注意一点 如果是破解版本的话 并发布自己的游戏的话 一定要修改 buldle indefiler 包名 否则会发布不成功
修改好后 选择 build Setting 窗口中的 bulid 按钮&
开始生成 android 游戏的apk 了 &第一次生成过程中会让选择 android-sdk 的目录 选择即可 &生成完成后可以在刚刚保存apk 的地方找到那个apk 了&
我用的版本是 3.4.0 & &手机摩托罗拉me525 &下面看看游戏运行效果
附件下载地址:
后面我会继续写一些这套游戏引擎方面的文章,哇咔咔~~ 欢迎广大盆友们可以和我一起交流 大家一起学习 & 同时欢迎各位朋友拍砖 和 有什么不对的地方 欢迎大家提出..本文出自 “” 博客,请务必保留此出处
了这篇文章
类别:┆阅读(0)┆评论(0)
21:02:32 23:11:58 03:21:31 16:36:09 22:55:51 13:16:13Assetbundle的杂七杂八 - yaol - 博客园
转自 http://www.unitymanual.com/blog-.html
1.Editor版本不能读取与自己版本不同的assetbundle这个问题描述起来很简单:比如:老板原来让你用4.1打包(BuildAssetBundle)开发,开发完毕后,下半年,unity升级了, 于是老板要求与时俱进,让你用4.3开发维护,这时,问题就出现了:4.1下的editor打包的assetbundle在editor下不能被4.3读 取,会报错。那么解决方法是啥呢?把所有资源重新在4.3下打包。很坑吧?但是,这问题仅仅只是在editor下会出现,webplayer不会出现。但你恐怕很少说调试程序不走editor吧?
2.assetbundle如果从WWW中被读取过一次,再读取会报错当你把assetbundle资源用www下载下来后,往往都会使用&wwwResource.assetbundle&,但是注意,这个函数调用assetbundle的时候,只能调用一遍。意思是,当你要再次读取的时候,会报错。这时候,需要你写一套对于assetbundle的控制程序,保证第一次读取资源的时候是使用wwwResource.assetbundle,第二次再次利用,则要用已经读取出来的资源。
3.慎用BuildPipeline的PushAssetDependencies()和PopAssetDependencies()功能在我们的项目中,打包时,用到了BuildPipeline.PushAssetDependencies()和 BuildPipeline.PopAssetDependencies()的功能,这是unity里比较好的一项功能,它可以把unity里的依赖关系 比较好的保存下来,并正常读取就可以还原。比如:一个模型用到了贴图1,贴图2,贴图3,这时,我们可以用这种依赖关系的方式,把模型单独打出来,同时把 贴图1贴图2贴图3也单独打包出来,这样的话,如果有别的模型也用到了贴图123,只需要下载一次,然后在读进工程的时候,贴图自动找到模型,并贴上去。 听起来很美,但是也有问题:严格根据依赖关系按顺序下载资源。否则,留给你的是一个个白模。我们被这个问题坑了好久。
4.Unity编译的webplayer工程,免费cache只有50MB听起来是不是好惊讶?webplayer下的免费cache居然这么少?意味着,在webplayer下,你的LoadFromCacheOrDownload用处并不是非常大。因为你的资源需要一遍又一遍的下载,cache的作用大大缩小了。而如果你想扩展,需要联系他们的销售部,据说价格不菲。不过针对这个问题,现在有人已经利用游览器的缓存绕过了这个问题,思路比较巧妙,但是涉及到unity官方利益,我在这里就不介绍了。
1、Assetbundle打包时需要使用 BuildTarget.iPhone 参数。不同发布平台打包的文件是不通用的。
2、当上传已经打包好的文件到FTP服务器时,注意在上传软件菜单里选择传输类型为二进制格式,而不是默认的 ASCII 格式。
AssetBundles (Pro only)
AssetBundles are files which you can export from Unity to contain assets of your choice. These files use a proprietary compressed format and can be loaded on demand by your application. This allows you to stream in content, such as models, textures, audio clips, or even entire scenes separately from the scene in which they will be used. AssetBundles have been designed to simplify downloading content to your application. AssetBundles can contain any kind of asset type recognized by Unity, as determined by the filename extension. If you want to include files with custom binary data, they should have the extension ".bytes". Unity will import these files as TextAssets.
When working with AssetBundles, here's the typical workflow:
During development, the developer prepares AssetBundles and uploads them to a server.
& & & & & & & & &
& & &Building and uploading asset bundles
Building AssetBundles. Asset bundles are created in the editor from assets in your scene. The Asset Bundle building process is described in more detail in the section for&
Uploading AssetBundles to external storage. This step does not include the Unity Editor or any other Unity channels, but we include it for completeness. You can use an&&to upload your Asset Bundles to the server of your choice.
At runtime, on the user's machine, the application will load AssetBundles on demand and operate individual assets within each AssetBundle as needed.
Downloading AssetBundles and loading assets from them
Downloading AssetBundles at runtime from your application. This is done from script within a Unity scene, and Asset Bundles are loaded from the server on demand. More on that in&.
Loading objects from AssetBundles. Once the AssetBundle is downloaded, you might want to access its individual Assets from the Bundle. More on that in&
Please read this section of the documentation thoroughly to familiarize yourself with the workflow for using AssetBundles, discover the different features they provide and learn best practices that can save you time and effort during development.
Building AssetBundles
There are three class methods you can use to build AssetBundles:
&allows you to build AssetBundles of any type of asset.
&is used when you want to include only scenes to be streamed and loaded as the data becomes available.
&is the same as BuildPipeline.BuildAssetBundle but has an extra parameter to specify a custom string identifier (name) for each object.
An example of how to build an AssetBundle
Building asset bundles is done through editor scripting. There is basic example of this in the scripting documentation for&.
BuildPipeline.BuildAssetBundle
static function BuildAssetBundle(mainAsset: Object, assets: Object[], pathName: string): bool;
static function BuildAssetBundle(mainAsset: Object, assets: Object[], pathName: string, assetBundleOptions: BuildAssetBundleOptions): bool;
static function BuildAssetBundle(mainAsset: Object, assets: Object[], pathName: string, assetBundleOptions: BuildAssetBundleOptions, targetPlatform: BuildTarget): bool;
Description
Builds an asset bundle (Unity Pro only).
Creates a compressed unity3d file that contains a collection of assets. AssetBundles can contain any asset found in the project folder. This lets you stream resource data of any type, fully setup prefabs, textures, meshes, animations, any type of asset shown in the project window. mainAsset lets you specify a specific object that can be conveniently retrieved using AssetBundle.mainAsset. The compressed asset bundle file will be saved at pathName. options allows you to automatically include dependencies or always include complete assets instead of just the exact referenced objects. All paths are relative to the project folder. Like: "AssetsMyTextureshello.png"
Note that asset bundles built for standalone or webplayer targets cannot be loaded by applications built for mobile platforms and vice versa. Furthermore, bundles are not compatible between iOS and Android platforms.
See Also: AssetBundle class, WWW.assetBundle.
// C# Example
// Builds an asset bundle from the selected objects in the project view.
// Once compiled go to "Menu" -& "Assets" and select one of the choices
// to build the Asset Bundle
using UnityE
using UnityE
public class ExportAssetBundles {
[MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")]
static void ExportResource () {
// Bring up save panel
string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0) {
// Build the resource file from the active selection.
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | pleteAssets);
Selection.objects =
[MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")]
static void ExportResourceNoTrack () {
// Bring up save panel
string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0) {
// Build the resource file from the active selection.
BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path);
BuildAssetBundle
For the sake of this example, copy and paste the script from the link above into a new C# script called ExportAssetBundles. This script should be placed in a folder named Editor, so that it works inside the Unity Editor.
Now in the&Assets&menu, you should see two new menu options.
Build AssetBundle From Selection - Track dependencies. This will build the current object into an asset bundle and include all of its dependencies. For example if you have a prefab that consists of several hierarchical layers then it will recursively add all the child objects and components to the asset bundle.&
Build AssetBundle From Selection - No dependency tracking. This is the opposite of the previous method and will only include the single asset you have selected.
For this example, you should create a new prefab. First create a new Cube by going to&GameObject -& Create Other -& Cube, which will create a new cube in the Hierarchy View. Then drag the Cube from the Hierarchy View into the Project View, which will create a prefab of that object.
You should then right click the Cube prefab in the project window and select&Build AssetBundle From Selection - Track dependencies. At this point you will be presented with a window to save the "bundled" asset. If you created a new folder called "AssetBundles" and saved the cube as&Cube.unity3d, your project window will now look something like this.
At this point you can move the AssetBundle&Cube.unity3d&elsewhere on your local storage, or upload it to a server of your choice.
An example of how to change the properties of the assets when building an Asset Bundle
You can use&&to force reimporting the asset right before calling&, and then use&&to set the required properties. The following example will show you how to set different texture compressions when building the Asset Bundle.
// Builds an asset bundle from the selected objects in the project view,
// and changes the texture format using an AssetPostprocessor.
using UnityE
using UnityE
public class ExportAssetBundles {
// Store current texture format for the TextureProcessor.
public static TextureImporterFormat textureF
[MenuItem("Assets/Build AssetBundle From Selection - PVRTC_RGB2")]
static void ExportResourceRGB2 () {
textureFormat = TextureImporterFormat.PVRTC_RGB2;
ExportResource();
[MenuItem("Assets/Build AssetBundle From Selection - PVRTC_RGB4")]
static void ExportResourceRGB4 () {
textureFormat = TextureImporterFormat.PVRTC_RGB4;
ExportResource();
static void ExportResource () {
// Bring up save panel.
string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0) {
// Build the resource file from the active selection.
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
foreach (object asset in selection) {
string assetPath = AssetDatabase.GetAssetPath((UnityEngine.Object) asset);
if (asset is Texture2D) {
// Force reimport thru TextureProcessor.
AssetDatabase.ImportAsset(assetPath);
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | pleteAssets);
Selection.objects =
// Changes the texture format when building the Asset Bundle.
using UnityE
using UnityE
public class TextureProcessor : AssetPostprocessor
void OnPreprocessTexture() {
TextureImporter importer = assetImporter as TextureI
importer.textureFormat = ExportAssetBundles.textureF
You can also control how the asset is imported using the&.
In a test environment, you sometimes need to test a change that require AssetBundles to be rebuilt. In these cases, it is advisable to use the option&&when you build the AssetBundles. This makes it faster to build and load the AssetBundles but they will also be bigger and therefore take longer to download.
Building AssetBundles in a production enviroment
When first using AssetBundles it may seem enough to manually build them as seen in the previous example. But as a project grows in size and the number of assets increases doing this process by hand is not efficient. A better approach is to write a function that builds all of the AssetBundles for a project. You can, for example, use a text file that maps Asset files to AssetBundle files.
Streaming Assets
Contains the path to the game data folder (Read Only).
The value depends on which platform you are running on:
Unity Editor:&&path to project folder&/Assets
Mac player:&&path to player app bundle&/Contents
iPhone player:&&path to player app bundle&/&AppName.app&/Data
Win player:&&path to executablename_Data folder&
Web player:&The absolute url to the player data file folder (without the actual data file name)
Flash:&The absolute url to the player data file folder (without the actual data file name)
Note that the string returned on a PC will use a forward slash as a folder separator.
Application.streamingAssetsPath
Contains the path to the StreamingAssets folder (Read Only).
If you have a "StreamingAssets" folder in the Assets folder of your project, it will be copied to your player builds and be present in the path given by Application.streamingAssetsPath.
Any files placed in a folder called StreamingAssets in a Unity project will be copied verbatim to a particular folder on the target machine.
It's always best to use&&to get the location of the StreamingAssets folder, it will always point to the correct location on the platform where the application is running.
Most assets in Unity are combined into the project when it is built. However, it is sometimes useful to place files into the normal filesystem on the target machine to make them accessible via a pathname. An example of this is the deployment of a movie file on iOS the original movie file must be available from a location in the filesystem to be played by the PlayMovie function.
Note that on some platforms it is not possible to directly access the StreamingAssets folder because there is no file system access in the web platforms, and because it is compressed into the .apk file on Android. On those platforms, a url will be returned, which can be used using the WWW class.
// print the path to the streaming assets folder
var filePath = System.bine(, "MyFile");
var result = "";
if (filePath.Contains("://"))
var www = new
(filePath);
result = www.
result = System.IO.File.ReadAllText(filePath);
You can retrieve the folder using the&property. For reference, the location of this folder varies per platform:
On a desktop computer (Mac OS or Windows) the location of the files can be obtained with the following code:
path = Application.dataPath + "/StreamingAssets";
On iOS, you should use:
path = Application.dataPath + "/Raw";
...while on Android, you should use:
path = "jar:file://" + Application.dataPath + "!/assets/";
Note that on Android, the files are contained within a compressed .jar file (which is essentially the same format as standard zip-compressed files). This means that if you do not use Unity's WWW class to retrieve the file then you will need to use additional software to see inside the .jar archive and obtain the file.
Unity 3D : 製作與載入 AssetBundle
通常我們在遊戲程式執行過程,並不希望一次將全部的資源都載入,而比較希望實際上有使用到的才載入,以免佔用多餘的記憶體,所以我們可能會儘量規劃好不同功能的場景,在需要時才載入場景並釋放掉前個場景中不需要的資源,或是將資源放在 Resource 資料夾中,在真正需要時才利用 Resources.Load() 把資源載入;這些都是不錯的管理方法,但是當我們遊戲中的資源相當多時,輸出的程式還是會相當龐大,而且如果是時常會更新內容資源的遊戲,也會因為龐大的資源而造成編譯輸出時要花相當多的時間;特別是手機或網頁遊戲,幾乎輸出最後的結果只是一個檔案而已,這個檔案如果很龐大,將可能造成下載或啟動遊戲的不方便;這時候我們可能就要考慮製作 AssetBundle。製作與遊戲主程式分離的資源包可以得到某程度上的好處,我們可以讓遊戲主程式只管理遊戲邏輯的部份,當有需要某些資源則從外部的 AssetBundle 載入資源,這樣一來,如果有任何遊戲更新只是添加或更換資源,並沒有變更到遊戲程式邏輯或內容部署,我們只需要重新打包資源的部份就能完成更新,而不再需要整個遊戲重新編譯輸出。例如我們有已上架的 iPhone 遊戲,因為特定節日想把遊戲內的圖片換成另一種氣氛,通常就必須要重新輸出,然後送審,等節日過後又想把圖片換回原本的,要再次輸出遊戲,再送審,一方面送審費時費工,另一方面是從送審到架上遊戲更新完成的時間,我們並不能準確掌控;如果事先將資源分離打包成 AssetBundle 儲存在我們自己管理的伺服器中,在這種需要換圖的時刻,只需要打包自行在伺服器中將 AssetBundle 更新即可,可以省掉不斷送審的麻煩,時間上也更能掌控,另外就是遊戲主程式中沒有龐大的資源資料,主程式也就會小一點,那麼玩家要下載我們的遊戲也會更快速些。還有就是,我們輸出為網頁遊戲時一定會發現到,輸出結果只是一個 html 檔及一個 unity3d 檔,應該有寫過網頁的人都知道,網頁的運作是瀏覽器將網頁中的文件、圖片、音樂、影像... 等等的資料下載到客戶端暫存之後再執行呈現出結果,那麼如果我們遊戲內容的龐大資源都與主程式編在一起的話,那麼輸出後的 unity3d 檔應該也會不小,此時我們可能要思考一下,我們希望玩家花多久時間完成啟動頁面再進行遊戲呢?也許 Unity 的 Web Player 有辦法解決這個問題使玩家不會花太多時間啟動頁面(這部份我就比較不確定了^_^),但是正因為網頁的運作方式是如此,所以當我們在伺服器端更新時,玩家只要沒有重新載入頁面,玩到的遊戲內容始終是舊版的,此時又要考慮到,如果沒有更新遊戲邏輯或內容規則的情況下,是否有必要強制玩家中斷遊戲重新載入頁面;如果將資源都打包成 AssetBundle 分離出來,那麼 unity3d 檔這個主程式的部份將會變得更小,而當有任何資源更新時只需要在伺服器端將 AssetBundle 的檔案換掉,玩家不需要重新載入頁面一樣能體驗到更新後的內容。以上寫了一大堆,主要就是要說明 AssetBundle 是個很重要又好用的東西,畢竟在沒變更程式或遊戲部署的情況下,沒必要去重新 Build 遊戲主程式,以下就來說明如何製作 AssetBundle ...首先要使用【】的方法自定義選單命令,使我們能夠操作何時開始製作 AssetBundle 及如何做,接下來我們需要能夠指定哪些資源將打包成 AssetBundle,所以需要使用到 Editor class 的 Selection.GetFiltered(),還有就是要過濾哪些型別的資源才是我們要的,選擇錯誤則略過,不要處理,最後再使用 BuildPipeline.BuildAssetBundle() 建立 AssetBundle 即可,以下範例會在 Unity 專案資料夾(不是 Asset 資料夾)中建立 _AssetBunldes 資料夾用來存放打包好的 AssetBundle,打包的目標為 GameObject、Texture2D、Material 三種型別的資源,如果儲存檔案路徑檔名相同則會先刪除舊檔:[MenuItem("Custom Editor/Create AssetBunldes")]static void ExecCreateAssetBunldes(){// AssetBundle 的資料夾名稱及副檔名string targetDir = "_AssetBunldes";string extensionName = ".assetBunldes";//取得在 Project 視窗中選擇的資源(包含資料夾的子目錄中的資源)Object[] SelectedAsset = Selection.GetFiltered(typeof (Object), SelectionMode.DeepAssets);//建立存放 AssetBundle 的資料夾if(!Directory.Exists(targetDir)) Directory.CreateDirectory(targetDir);foreach(Object obj in SelectedAsset){//資源檔案路徑string sourcePath = AssetDatabase.GetAssetPath(obj);// AssetBundle 儲存檔案路徑string targetPath = targetDir + Path.DirectorySeparatorChar + obj.name + extensionNif(File.Exists(targetPath)) File.Delete(targetPath);if(!(obj is GameObject) && !(obj is Texture2D) && !(obj is Material))//建立 AssetBundleif(BuildPipeline.BuildAssetBundle(obj, null, targetPath, BuildAssetBundleOptions.CollectDependencies)){Debug.Log(obj.name + " 建立完成");}else{Debug.Log(obj.name + " 建立失敗");}}}以上是直接將選擇的資源打包成 AssetBundle,另外,你也可以在打包前依需求將型別為 GameObject 的資源 Instantiate 到場景中添加需要的 Component 並回到 Project 中建立 Prefab,最後再以這個 Prefab 打包成 AssetBundle,一切就看個人如何運用了。製作好的 AssetBundle 最終目的還是要在遊戲中載入,以下用簡短的範例在遊戲畫面上顯示一個按鈕,當按下按鈕之後載入型別為 GameObject 的 AssetBundle 並利用 Instantiate() 使其實例化而在場景中產生 GameObject:void OnGUI(){if(GUI.Button(new Rect(5,35,100,25) , "Load GameObject")){StartCoroutine(LoadGameObject());}}private IEnumerator LoadGameObject(){// AssetBundle 檔案路徑string path = string.Format("file://{0}/../_AssetBunldes/{1}.assetBunldes" , Application.dataPath , "TestGameObject");// &載入 AssetBundleWWW bundle = new WWW(path);//等待載入完成//實例化 GameObject 並等待實作完成yield return Instantiate(bundle.assetBundle.mainAsset);//卸載 AssetBundlebundle.assetBundle.Unload(false);}範例中的檔案路徑(path)字串是以此程式碼在 Unity 編輯器中執行為例,實作時應該以實際執行平台及個人喜好指定 AssetBundle 存放路徑,詳情可參考官方文件&說明;因為載入的資源必須要等待載入完成以確保遊戲運作正常,在 C# 使用 yield 除了回傳型別為 IEnumerator 之外,調用時也必須使用 StartCoroutine() 調用,如果使用 Javascript 則可直接呼叫該 function;如果 AssetBundle 已載入過,下次再請求載入將會出現 【The asset bundle '檔名' can't be loaded because another asset bundle with the same files are already loaded】的錯誤訊息,即使使用區域變數(範例中的 bundle)仍然會得到這個錯誤訊息,所以必須在每次載入使用完後將 AssetBundle 卸載;另外,要特別注意的是載入 AssetBundle 到卸載期間可能消耗些微時間,如果連續調用載入同一個 AssetBundle,造成在卸載前重複載入也可能出現前面的錯誤訊息,所以,最好是能定義個陣列或其它變數來記錄載入中的 AssetBundle 有哪些,以此變數內容在載入 AssetBundle 前檢查。

我要回帖

更多关于 unity 打开文件对话框 的文章

 

随机推荐