原文出自: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. spring boot 以jar的方式启动常用shell脚本

    用spring boot框架做的项目,将第三方包全部打在jar里面,通过shell脚本启动和停止服务,常用的shell脚本模板如下: #!/bin/bashJAVA_OPTIONS_INITIAL=- ...

  2. C#中字符串的内存分配与驻留池

    完全引用http://www.cnblogs.com/instance/archive/2011/05/24/2056091.html 驻留池:是一张记录了所有在代码中使用字面量声明的字符串实例的引用 ...

  3. Incomplete response received from application

    RAILS_ENV=production rake secret 将输出的一大串字码粘贴到rails工程中/config/secrets.yml去,替换掉该文件中的<%= ENV["S ...

  4. image has dependent child images

    在删除镜像之前要先用 docker rm 删掉依赖于这个镜像的所有容器(哪怕是已经停止的容器),否则无法删除该镜像. 停止容器 # docker stop $(docker ps -a | grep ...

  5. asp.net 在AcquireRequestState事件中判断登陆验证。

    Global中添加AcquireRequestState事件. protected void Application_AcquireRequestState(object sender, EventA ...

  6. 计算机网络概述 传输层 TCP可靠传输的实现

    TCP可靠传输的实现 TCP的可靠性表现在:它向应用层提供的数据是 无差错的.有序的.无丢失的,简单的说就是:TCP最终递交给应用层的数据和发送者发送的数据是一模一样的. TCP采用了流量控制.拥塞控 ...

  7. 【Head First Servlets and JSP】笔记6:什么是响应首部 & 快速搭建一个简单的测试环境

    搭建简单的测试环境 什么是响应首部 最简单的响应首部——Content-Type 设置响应首部 请求重定向与响应首部 在浏览器中查看Response Headers 1.先快速搭建一个简单的测试环境, ...

  8. Squid 反向代理配置

    Squid 反向代理配置 1.删除主配置文件重写写入配置 rm -f /etc/squid/squid.conf 2.重新写入配置反向代理 vim /etc/squid/squid.conf # 监听 ...

  9. INSPIRED启示录 读书笔记 - 第32章 提防有特殊要求的产品

    产品需求不能用户说了算 1.在看到具体的产品之前,用户很难知道自己需要什么 2.用户不知道什么样的产品是可行的(在目前的技术条件下可以实现) 3.用户之间缺少沟通,需求很难统一 怎样回避特例产品可能带 ...

  10. codeforces 435B

    题意:只能对相邻的两个数字进行交换,允许k次交换,输出交换能得到的最大的数.从最高位开始寻找最优,每次寻找能交换的步数里交换到的最大值进行交换. #include<cstdio> #inc ...