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>

unity3d格式的导出与加载的更多相关文章

  1. Unity3d Web3d资源的动态加载

    Unity3d Web3d资源的动态加载 @灰太龙 参考了宣雨松的博客,原文出处http://www.xuanyusong.com/archives/2405,如果涉及到侵权,请通知我! Unity3 ...

  2. unity3d进行脚本资源打包加载

    原地址:http://www.cnblogs.com/hisiqi/p/3204752.html 本文记录如何通过unity3d进行脚本资源打包加载 1.创建TestDll.cs文件 public c ...

  3. 【Unity3D】Unity3D之 Resources.Load 动态加载资源

    [Unity3D]Unity3D之 Resources.Load 动态加载资源 1.Resources.Load:使用这种方式加载资源,首先需要下Asset目录下创建一个名为Resources的文件夹 ...

  4. KEngine:Unity3D资源的打包、加载、调试监控

    资源模块做什么? 资源模块——ResourceModule,是KEngine中最核心的模块,其他模块基本或多或少的对它有依赖,它主要的功能是:资源打包.路径定义.资源管理.资源调试. 资源模块对Uni ...

  5. unity3d 加密资源并缓存加载

    原地址:http://www.cnblogs.com/88999660/archive/2013/04/10/3011912.html 首先要鄙视下unity3d的文档编写人员极度不负责任,到发帖为止 ...

  6. C#用ckplayer.js播放 MP4格式视频实现 边加载边播放

    MVC设计模式下 在View页面里面使用ckplayer.js 加载视频 ,在MP4格式视频上传之后 我发现某些视频可以边加载边播放 但是有一些又不行,找了下原因是因为视频的元数据信息在第一帧的时候就 ...

  7. (转)unity3d加密资源并缓存加载

    http://www.haogongju.net/art/1931680 首先要鄙视下unity3d的文档编写人员极度不负责任,到发帖为止依然没有更新正确的示例代码. view source   pr ...

  8. Unity3D AssetBundle的打包与加载

    在Unity项目开发过程中,当要做热更新时常常使用一个叫做AssetBundle的东西,这里做一点个人的学习记录 步骤1: 设置打包标签:具体步骤----进入Unity,选择某一资源然后看右下角,在那 ...

  9. Unity3D在移动平台下加载AssetBundle导致Shader效果不正确的问题

    这个问题,主要还是在移动平台下开发导致的. 在编辑器里调试加载AB时会导致Shader效果不正确的原因,主要还是编辑器下加载以IOS或是ANDROID平台打包的AB它所使用的shader已经编译成对应 ...

随机推荐

  1. Java面向对象和特征

    面向对象: 概念: 面向对象是一种程序设计思想,计算机程序的设计实质上就是将现实中的一些事物的特征抽离出来描述成一些计算机事件的过程,这种抽象的过程中,我们把具体的事物封装成一个一个的整体进行描述,使 ...

  2. logstash日志写到es,按照时间来进行切割,生成索引配置

    配置如下: es创建索引使用: logstash-chat-proxy-nginx-access-* logstash-chat-proxy-nginx-error-*

  3. 初识C#设计模式

    利用设计模式可以使我们的代码更灵活,更容易扩展,更容易维护.各种面向对象的程序设计语言都提供了基本相同的机制:比如类.继承.派生.多态等等.但是又有各自的特色,C# 中的反射机制便是一个很重要的工具, ...

  4. 【BZOJ 3238】【AHOI 2013】差异

    http://www.lydsy.com/JudgeOnline/problem.php?id=3238 后缀数组裸题但是\(5\times 10^5\)貌似常数有点大就过不了?(我的sa常数那么大想 ...

  5. Line Reflection -- LeetCode

    Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given ...

  6. 初见Python<1>:基础语法

    1.两个整数相除,计算结果的小数部分被截除,结果仍然是一个整数: 如:1/2=0 2.整数和浮点数相除.或者浮点数之间相除,结果有小数部分,仍然是一个浮点数: 如:1/2.0=0.5  1.0/2=0 ...

  7. [NOI2016]循环之美(杜教筛)

    首先要求每个数互不相等,故有$x\perp y$. 可以发现$\frac{x}{y}$在$k$进制下为纯循环小数的充要条件为$x\cdot k^{len}\equiv x(mod\ y)$,即$y\p ...

  8. [UOJ347]通道

    锟题x1 以下用$d_k(x,y)$表示$x,y$在第树$k$上的距离,$h_k(x)$表示$x$在树$k$上的深度 先做两棵树,即最大化$d_1(x,y)+d_2(x,y)=h_1(x)+h_1(y ...

  9. ubuntu中使用apt-get install 安装的软件的一些目录所在地

    apt-get 所下载的用于安装的软件包,在 /var/cache/apt/archives中.如果执行过 apt-get clean ,那么原始下载的包就找不到了. 1.下载的软件存放位置/var/ ...

  10. Inno Setup入门(十九)——Inno Setup类参考(5)

    单选按钮 单选按钮在安装中也很常见,例如同一个程序可以选择安装不同的性质的功能,例如选择32位或者64位等,两者是排他性的,因此可以通过单选按钮(RadioButton)来实现,在同一个容器中放置的单 ...