BuildPipeline.BuildAssetBundle 编译资源包
原文出自:http://blog.csdn.net/nateyang/article/details/7567831
1.导出。unity3d格式资源:
http://game.ceeger.com/Script/BuildPipeline/BuildPipeline.BuildAssetBundle.html
这里我稍微改了一点点~~~代码如下:
- using UnityEngine;
- using UnityEditor;
- using System.IO;
- public class BuildAssetBundlesFromDirectory {
- [@MenuItem("Asset/Build AssetBundles From Directory of Files")]
- static void ExportAssetBundles () {
- // Get the selected directory
- //获取选择的目录
- string path = AssetDatabase.GetAssetPath(Selection.activeObject);
- Debug.Log("Selected Folder: " + path);
- if (path.Length != 0) {
- path = path.Replace("Assets/", "");
- string [] fileEntries = Directory.GetFiles(Application.dataPath+"/"+path);
- foreach(string fileName in fileEntries) {
- string filePath = fileName.Replace("\\","/");
- int index = filePath.LastIndexOf("/");
- filePath = filePath.Substring(index+1);
- Debug.Log("filePath:"+filePath);
- string localPath = "Assets/" + path+"/";
- if (index > 0)
- localPath += filePath;
- Object t = AssetDatabase.LoadMainAssetAtPath(localPath);
- if (t != null) {
- Debug.Log(t.name);
- string bundlePath = "Assets/" + path + "/" + t.name + ".unity3d";
- Debug.Log("Building bundle at: " + bundlePath);
- // Build the resource file from the active selection.
- //从激活的选择编译资源文件
- BuildPipeline.BuildAssetBundle
- (t, null, bundlePath, BuildAssetBundleOptions.CompleteAssets);
- }
- }
- }
- }
- }
注意:string filePath = fileName.Replace("\\","/"); 把“\”转化成“/”。“Assets/path/.prefab”和“path\.prefab”
把以上代码的脚本放到一个文件夹里面,选中该文件夹,再点击菜单栏上的按钮"Asset/Build AssetBundles From Directory of Files",就成功转成unity3d格式了
2.加载.unity3d:
- function Start () {
- var www = new WWW ("file:///"+Application.dataPath+"/resourse/Cube.unity3d");
- yield www;
- Instantiate(www.assetBundle.mainAsset);
- }
注:Application.dataPath获取改程序的资源路径。
- function Start ()
- {
- var www = WWW.LoadFromCacheOrDownload("http://210.30.12.33:8080/YangChun/file/Cube.unity3d",5);
- yield www;
- if (www.error != null)
- {
- Debug.Log (www.error);
- return;
- }
- Instantiate(www.assetBundle.mainAsset);
- }
我试了一下用Resources类的方法还不能加载unity3d格式的文件。不过如果是本地加载的话直接加载prefab就可以了,用不着用unity3d格式了。貌似
- LoadFromCacheOrDownload方法只能加载.unity3d格式文件,我用Tomcat服务器小测了一下,可以达到缓存的效果。
3.加载场景的话:
先把场景转化成unity3d格式的。
注:以下代码的脚本必须放在Editor文件夹下(如果没有改文件,新建一个就行),BuildTarget注意哈,转化成不同的平台~~~BuildTarget.Andrdoid
- <pre name="code" class="java">@MenuItem ("Build/BuildWebplayerStreamed")
- static function MyBuild(){
- var levels : String[] = ["Assets/yaya.unity"];
- BuildPipeline.BuildStreamedSceneAssetBundle( levels, "yaya.unity3d", BuildTarget.WebPlayer);//BuildTarget.Andrdoid
- }
- </pre>或者
- <pre></pre>
- <pre name="code" class="java" style="background-color: rgb(255, 255, 255); "><pre name="code" class="java">@MenuItem ("Build/BuildWebplayerStreamed")
- static function MyBuild(){
- BuildPipeline.BuildPlayer(["Assets/main.unity"],"VR.unity3d",BuildTarget.WebPlayer, BuildOptions.BuildAdditionalStreamedScenes);
- }</pre><br>
- <br>
- <br>
- <pre></pre>
- <pre style="margin-top:0px; margin-bottom:0px; background-color:rgb(238,238,238); font-family:Verdana,Geneva,sans-serif,宋体; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; white-space:pre-wrap; word-wrap:break-word; color:rgb(53,47,40); line-height:20px"><pre name="code" class="java">function Start () {
- // Download compressed scene. If version 5 of the file named "Streamed-Level1.unity3d" was previously downloaded and cached.
- // Then Unity will completely skip the download and load the decompressed scene directly from disk.
- //下载压缩的场景。如果名为Streamed-Level1.unity3d的文件版本为5,预先下载并缓存。
- //然后Unity将完全跳过下载并直接从磁盘加载解压的场景。
- var download = WWW.LoadFromCacheOrDownload ("http://210.30.12.16:8080/chunge/yaya.unity3d", 5);
- yield download;
- // Handle error
- if (download.error != null)
- {
- Debug.LogError(download.error);
- return;
- }
- // In order to make the scene available from LoadLevel, we have to load the asset bundle.
- // The AssetBundle class also lets you force unload all assets and file storage once it is no longer needed.
- //为了使场景LoadLevel可用,必须加载资源包
- //AssetBundle类,还可以强制卸载所有的资源和文件存储,一旦不再需要。
- var bundle = download.assetBundle;
- // Load the level we have just downloaded
- //加载刚才下载的关卡
- Application.LoadLevel ("yaya");//这里面的“yaya”是指“Assets/yaya.unity”而不是指“yaya.unity3d”
- }</pre><br><br></pre>
- <br>
- <br>
- <br>
- <p></p>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- </pre>
BuildPipeline.BuildAssetBundle 编译资源包的更多相关文章
- unity 打包资源及网络请求资源包
第一步 导包 在Assets新建一个Editor目录 新建一个Test类 using UnityEngine; using System.Collections; using UnityEditor; ...
- Unity3D基础学习之AssetBundle 资源包创建与加载
前几天做了AssentBundle的例子,遇到了问题,在论坛上问了三天都没人解答,最后在一个朋友的帮助下解决了.下面介绍AssentBundle. AssetBundles让你通过WWW类流式加载额外 ...
- iOS 中 .a 和 .framework 静态库的创建与 .bundle 资源包的使用
iOS 中 .a 和 .framework 静态库的创建与 .bundle 资源包的使用 前言 开发中经常使用三方库去实现某特定功能,而这些三方库通常又分为开源库和闭源库.开源库可以直接拿到源码,和自 ...
- 【反编译系列】一、反编译代码(dex2jar + jd-gui)和反编译资源(apktool)
版权声明:本文为HaiyuKing原创文章,转载请注明出处! [反编译系列]二.反编译代码(jeb) [反编译系列]三.反编译神器(jadx) [反编译系列]四.反编译so文件(IDA_Pro) 概述 ...
- protobuf 在win10系统如何编译jar包
最近在搞java服务器项目,前段要求用protobuf进行数据传输,以前没搞过,查了很多资料,走了一些弯路! 先把一些需要下载的链接放上来: protobuf下载地址:https://github.c ...
- Android 添加framework资源包
为Android系统添加一个新的资源包 概述 传统的Android系统只有一个framework-res.apk资源包,第三方厂商在进行rom定制时会直接修改framework res资源,达到适配目 ...
- linux 中部署ant编译的包中缺少问题
今天遇到在window上部署ant编译的包,能运行正常,但部署在linux中出现跳不进jsp中,出现404问题,后来经过排查在jsp中<%@taglib prefix="c" ...
- Unity3D内置资源包简介
Custom Package:倒入第三方的资源包,如果资源包存在中文路径,很容易导入入失败. Character Controller:角色控制相关脚本,第一第三人称的prefab; Glass Re ...
- jad 反编译 jar包
1.利用winrar解压缩jar包 或者CMD>jar -xvf test.jar -C classes 2.下载jad,利用jad反编译jar包 CMD>[jad_home]/jad.e ...
随机推荐
- 20160419 while练习,复习
10 一.while和if题目练习 . 二.知识拓展 1. C#中的委托是什么?事件是不是一种委托? 答 : 委托可以把一个方法作为参数代入另一个方法.委托可以理解为指向一个函数的引用. ...
- iOS 几种常用的 crash log 崩溃信息调试方法
前言:crash log 对 定位崩溃问题 ,并且不容易复现,尤其是及时对appstore 上正在运营的 app 的迭代改进来说 非常重要. 1 crash两种情况 1.1 测试环境下 追踪bug 1 ...
- UI控件之UIImageView
UIImageView:图像视图,用于在应用程序中显示图片 UIImage:是将图片文件转换为程序中的图片对象 UIImageView是UIImage的载体 方法一:用此方法创建图片对象,会将图片ca ...
- mysql库安装
如果缺少<mysql/mysql.h> 先安装mysql,然后apt-get install libmysqlclient-dev即可
- Eclipse Class Decompiler——Java反编译插件
http://www.blogjava.net/cnfree/archive/2012/10/30/390457.html Eclipse Class Decompiler是一款Eclipse插件,整 ...
- Model FEP 快易播看板推播系统
主要特色: 低成本,快速导入 透过Wi-Fi 方式推播,现场架设容易 采Web Browser 介面登入操作,简单快速 模组化版面设定,弹性调整资料呈现方式 可整合多种连线方式与外部资料库沟通 可自行 ...
- PHP辅攻_[学习资料收集]PHP连接SQLServer2005方法
PHP连接SQLServer2005 1.修改php.ini将extension=php_mssql.dll的注释删除保存. 修改php.in将mssql.secure_connection = Of ...
- bash脚本之读取数据
题目: 一个tab间隔的文件,读取时一行为一个循环,依次读取每行的参数. 比如第一行为:a b c ,输出为a+b+c #/bin/bash while read id do a=($id) b=${ ...
- indy10 UDP实例
UDP就比较简单了,放个按钮,一个TIdUDPServerTIdUDPServer绑定 0.0.0.0:3820,然后Active设置为True //发送按钮procedure TForm1.Butt ...
- 20145230《Java程序设计》第4周学习总结
20145230<Java程序设计>第4周学习总结 教材学习内容总结 继承共同行为 本周学习的首先是Java语言中的继承与多态.何为我们的继承呢?在我们面向对象中,子类继承父类,避免重复的 ...