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. 关于Spring和SpringMVC的一点感悟

    一年前,我们项目最开始使用的SSH(spring+springmvc+hibernate),那时候项目经理搭建好了框架就交给了我们,后来在一次配置事务的过程中,出现了大名鼎鼎的no seesion. ...

  2. 洛谷——P3908 异或之和

    P3908 异或之和 题目描述 求1 \bigoplus 2 \bigoplus\cdots\bigoplus N1⨁2⨁⋯⨁N 的值. A \bigoplus BA⨁B 即AA , BB 按位异或. ...

  3. css总结——position

    CSS(Cascading Style Sheet),中文翻译为层叠样式表,是用于控制网页样式并允许将样式信息与网页内容分离的一种标记性语言.在css控制页面中,主要有四种样式:行内样式(style ...

  4. 【最大流Dinic模板】HDU1532&POJ1273-Drainage Ditches(16/3/6更正)

    #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...

  5. PHP时间戳是10位的,JS时间戳是13位

    var dateStr = new Date(time * 1000);  

  6. RSA加密破解

    1Linux 下安装gmpy2 https://www.cnblogs.com/ESHLkangi/p/8576113.html 2.yafu安装使用方法 https://www.cnblogs.co ...

  7. OpenVPN官方资源下载和官方教程入口

    官方资源: https://openvpn.net/index.php/open-source/downloads.html 2.4.4版本下载:(链接: https://pan.baidu.com/ ...

  8. web安全之如何防止CSRF跨站请求伪造

    CSRF(Cross-site request forgery)跨站请求伪造,也被称为“One Click Attack”或者Session Riding,通常缩写为CSRF或者XSRF,是一种对网站 ...

  9. 课程学习:Linux系统管理

    版本 内核版本 发行版本 常见Linux发行版本 ubuntu: 易用,可靠:技术支持付费,生态稍弱 debin: 精简,稳定,可靠; 更新较慢, 无技术支持,软件过时, 企业不太用 opensuse ...

  10. 通配置文件的方式控制java.util.logging.Logger日志输出

    转自:http://zochen.iteye.com/blog/616151 简单的实现了下利用JDK中类java.util.logging.Logger来记录日志.主要在于仿照log4j方式用配置文 ...