原文出自:http://blog.csdn.net/nateyang/article/details/7567831

1.导出。unity3d格式资源:

http://game.ceeger.com/Script/BuildPipeline/BuildPipeline.BuildAssetBundle.html

这里我稍微改了一点点~~~代码如下:

  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.IO;
  4. public class BuildAssetBundlesFromDirectory {
  5. [@MenuItem("Asset/Build AssetBundles From Directory of Files")]
  6. static void ExportAssetBundles () {
  7. // Get the selected directory
  8. //获取选择的目录
  9. string path = AssetDatabase.GetAssetPath(Selection.activeObject);
  10. Debug.Log("Selected Folder: " + path);
  11. if (path.Length != 0) {
  12. path = path.Replace("Assets/", "");
  13. string [] fileEntries = Directory.GetFiles(Application.dataPath+"/"+path);
  14. foreach(string fileName in fileEntries) {
  15. string filePath = fileName.Replace("\\","/");
  16. int index = filePath.LastIndexOf("/");
  17. filePath = filePath.Substring(index+1);
  18. Debug.Log("filePath:"+filePath);
  19. string localPath = "Assets/" + path+"/";
  20. if (index > 0)
  21. localPath += filePath;
  22. Object t = AssetDatabase.LoadMainAssetAtPath(localPath);
  23. if (t != null) {
  24. Debug.Log(t.name);
  25. string bundlePath = "Assets/" + path + "/" + t.name + ".unity3d";
  26. Debug.Log("Building bundle at: " + bundlePath);
  27. // Build the resource file from the active selection.
  28. //从激活的选择编译资源文件
  29. BuildPipeline.BuildAssetBundle
  30. (t, null, bundlePath, BuildAssetBundleOptions.CompleteAssets);
  31. }
  32. }
  33. }
  34. }
  35. }

注意:string filePath = fileName.Replace("\\","/");  把“\”转化成“/”。“Assets/path/.prefab”和“path\.prefab”

把以上代码的脚本放到一个文件夹里面,选中该文件夹,再点击菜单栏上的按钮"Asset/Build AssetBundles From Directory of Files",就成功转成unity3d格式了

2.加载.unity3d:

  1. function Start () {
  2. var www = new WWW ("file:///"+Application.dataPath+"/resourse/Cube.unity3d");
  3. yield www;
  4. Instantiate(www.assetBundle.mainAsset);
  5. }
注:Application.dataPath获取改程序的资源路径。
  1. function Start ()
  2. {
  3. var www = WWW.LoadFromCacheOrDownload("http://210.30.12.33:8080/YangChun/file/Cube.unity3d",5);
  4. yield www;
  5. if (www.error != null)
  6. {
  7. Debug.Log (www.error);
  8. return;
  9. }
  10. Instantiate(www.assetBundle.mainAsset);
  11. }
      我试了一下用Resources类的方法还不能加载unity3d格式的文件。不过如果是本地加载的话直接加载prefab就可以了,用不着用unity3d格式了。貌似
  1. LoadFromCacheOrDownload方法只能加载.unity3d格式文件,我用Tomcat服务器小测了一下,可以达到缓存的效果。

3.加载场景的话:

先把场景转化成unity3d格式的。

注:以下代码的脚本必须放在Editor文件夹下(如果没有改文件,新建一个就行),BuildTarget注意哈,转化成不同的平台~~~BuildTarget.Andrdoid

    1. <pre name="code" class="java">@MenuItem ("Build/BuildWebplayerStreamed")
    2. static function MyBuild(){
    3. var levels : String[] = ["Assets/yaya.unity"];
    4. BuildPipeline.BuildStreamedSceneAssetBundle( levels, "yaya.unity3d", BuildTarget.WebPlayer);//BuildTarget.Andrdoid
    5. }
    6. </pre>或者
    7. <pre></pre>
    8. <pre name="code" class="java" style="background-color: rgb(255, 255, 255); "><pre name="code" class="java">@MenuItem ("Build/BuildWebplayerStreamed")
    9. static function MyBuild(){
    10. BuildPipeline.BuildPlayer(["Assets/main.unity"],"VR.unity3d",BuildTarget.WebPlayer, BuildOptions.BuildAdditionalStreamedScenes);
    11. }</pre><br>
    12. <br>
    13. <br>
    14. <pre></pre>
    15. <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 () {
    16. // Download compressed scene. If version 5 of the file named "Streamed-Level1.unity3d" was previously downloaded and cached.
    17. // Then Unity will completely skip the download and load the decompressed scene directly from disk.
    18. //下载压缩的场景。如果名为Streamed-Level1.unity3d的文件版本为5,预先下载并缓存。
    19. //然后Unity将完全跳过下载并直接从磁盘加载解压的场景。
    20. var download = WWW.LoadFromCacheOrDownload ("http://210.30.12.16:8080/chunge/yaya.unity3d", 5);
    21. yield download;
    22. // Handle error
    23. if (download.error != null)
    24. {
    25. Debug.LogError(download.error);
    26. return;
    27. }
    28. // In order to make the scene available from LoadLevel, we have to load the asset bundle.
    29. // The AssetBundle class also lets you force unload all assets and file storage once it is no longer needed.
    30. //为了使场景LoadLevel可用,必须加载资源包
    31. //AssetBundle类,还可以强制卸载所有的资源和文件存储,一旦不再需要。
    32. var bundle = download.assetBundle;
    33. // Load the level we have just downloaded
    34. //加载刚才下载的关卡
    35. Application.LoadLevel ("yaya");//这里面的“yaya”是指“Assets/yaya.unity”而不是指“yaya.unity3d”
    36. }</pre><br><br></pre>
    37. <br>
    38. <br>
    39. <br>
    40. <p></p>
    41. <pre></pre>
    42. <pre></pre>
    43. <pre></pre>
    44. </pre>

BuildPipeline.BuildAssetBundle 编译资源包的更多相关文章

  1. unity 打包资源及网络请求资源包

    第一步 导包 在Assets新建一个Editor目录 新建一个Test类 using UnityEngine; using System.Collections; using UnityEditor; ...

  2. Unity3D基础学习之AssetBundle 资源包创建与加载

    前几天做了AssentBundle的例子,遇到了问题,在论坛上问了三天都没人解答,最后在一个朋友的帮助下解决了.下面介绍AssentBundle. AssetBundles让你通过WWW类流式加载额外 ...

  3. iOS 中 .a 和 .framework 静态库的创建与 .bundle 资源包的使用

    iOS 中 .a 和 .framework 静态库的创建与 .bundle 资源包的使用 前言 开发中经常使用三方库去实现某特定功能,而这些三方库通常又分为开源库和闭源库.开源库可以直接拿到源码,和自 ...

  4. 【反编译系列】一、反编译代码(dex2jar + jd-gui)和反编译资源(apktool)

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! [反编译系列]二.反编译代码(jeb) [反编译系列]三.反编译神器(jadx) [反编译系列]四.反编译so文件(IDA_Pro) 概述 ...

  5. protobuf 在win10系统如何编译jar包

    最近在搞java服务器项目,前段要求用protobuf进行数据传输,以前没搞过,查了很多资料,走了一些弯路! 先把一些需要下载的链接放上来: protobuf下载地址:https://github.c ...

  6. Android 添加framework资源包

    为Android系统添加一个新的资源包 概述 传统的Android系统只有一个framework-res.apk资源包,第三方厂商在进行rom定制时会直接修改framework res资源,达到适配目 ...

  7. linux 中部署ant编译的包中缺少问题

    今天遇到在window上部署ant编译的包,能运行正常,但部署在linux中出现跳不进jsp中,出现404问题,后来经过排查在jsp中<%@taglib prefix="c" ...

  8. Unity3D内置资源包简介

    Custom Package:倒入第三方的资源包,如果资源包存在中文路径,很容易导入入失败. Character Controller:角色控制相关脚本,第一第三人称的prefab; Glass Re ...

  9. jad 反编译 jar包

    1.利用winrar解压缩jar包 或者CMD>jar -xvf test.jar -C classes 2.下载jad,利用jad反编译jar包 CMD>[jad_home]/jad.e ...

随机推荐

  1. 20160419 while练习,复习

    10 一.while和if题目练习 . 二.知识拓展 1. C#中的委托是什么?事件是不是一种委托? 答 :    委托可以把一个方法作为参数代入另一个方法.委托可以理解为指向一个函数的引用.     ...

  2. iOS 几种常用的 crash log 崩溃信息调试方法

    前言:crash log 对 定位崩溃问题 ,并且不容易复现,尤其是及时对appstore 上正在运营的 app 的迭代改进来说 非常重要. 1 crash两种情况 1.1 测试环境下 追踪bug 1 ...

  3. UI控件之UIImageView

    UIImageView:图像视图,用于在应用程序中显示图片 UIImage:是将图片文件转换为程序中的图片对象 UIImageView是UIImage的载体 方法一:用此方法创建图片对象,会将图片ca ...

  4. mysql库安装

    如果缺少<mysql/mysql.h> 先安装mysql,然后apt-get install libmysqlclient-dev即可

  5. Eclipse Class Decompiler——Java反编译插件

    http://www.blogjava.net/cnfree/archive/2012/10/30/390457.html Eclipse Class Decompiler是一款Eclipse插件,整 ...

  6. Model FEP 快易播看板推播系统

    主要特色: 低成本,快速导入 透过Wi-Fi 方式推播,现场架设容易 采Web Browser 介面登入操作,简单快速 模组化版面设定,弹性调整资料呈现方式 可整合多种连线方式与外部资料库沟通 可自行 ...

  7. PHP辅攻_[学习资料收集]PHP连接SQLServer2005方法

    PHP连接SQLServer2005 1.修改php.ini将extension=php_mssql.dll的注释删除保存. 修改php.in将mssql.secure_connection = Of ...

  8. bash脚本之读取数据

    题目: 一个tab间隔的文件,读取时一行为一个循环,依次读取每行的参数. 比如第一行为:a b c ,输出为a+b+c #/bin/bash while read id do a=($id) b=${ ...

  9. indy10 UDP实例

    UDP就比较简单了,放个按钮,一个TIdUDPServerTIdUDPServer绑定 0.0.0.0:3820,然后Active设置为True //发送按钮procedure TForm1.Butt ...

  10. 20145230《Java程序设计》第4周学习总结

    20145230<Java程序设计>第4周学习总结 教材学习内容总结 继承共同行为 本周学习的首先是Java语言中的继承与多态.何为我们的继承呢?在我们面向对象中,子类继承父类,避免重复的 ...