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. NIO使用Reactor模式遇到的问题

    关于Reactor模式,不再多做介绍,推荐Doug Lea大神的教程:Java 可扩展的IO 本来在Reactor的构造方法中完成一系列操作是没有问题的: public class Reactor i ...

  2. Ajax使用进阶

    关于Ajax的概念不再做解释了,我想通过三个小例子来让大家对Ajax有个清晰的认识.要学习它,必须从最基础最原始的方式开始认识,然后通过使用框架来提升效率,逐步认识它. 一.原生js版(注册的用户名是 ...

  3. git "Could not read from remote repository.Please make sure you have the correct access rights."解决方案

    我们在使用git clone 或其他命令的时候,有时候会遇到这类问题,如图: fatal: Could not read from remote repository.Please make sure ...

  4. CentOS7和CentOS6的主要区别

    了解一下就好 1.  文件系统的区别.CentOS6默认使用的是ext4的文件系统,而CentOS7使用的是xfs. 2.  硬盘默认调度算法不一样.CentOS6默认使用的是cfq,而CentOS7 ...

  5. Flask实战第66天:celery实现异步任务

    Celery文档:http://docs.celeryproject.org Celery 通过消息进行通信,用专用的工作线程不断监视任务队列以执行新工作. Celery需要消息传输来发送和接收消息. ...

  6. Hive 空指针(NPE)异常

    空指针NullPointerException 1 Hive之前的一些BUG [HIVE-9430] - NullPointerException on ALTER TABLE ADD PARTITI ...

  7. rxjava 视频

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha Rxjava-基础篇视频教程-Rxjava框架的使用-麦子学院 它的自我介绍,我们可以理 ...

  8. POJ2068 Nim 博弈论 dp

    http://poj.org/problem?id=2068 博弈论的动态规划,依然是根据必胜点和必输点的定义,才明白过来博弈论的dp和sg函数差不多完全是两个概念(前者包含后者),sg函数只是mex ...

  9. poj 1348 Period(KMP)

    Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  10. Nginx配置自签名的SSL证书(转载)

    要保证Web浏览器到服务器的安全连接,HTTPS几乎是唯一选择.HTTPS其实就是HTTP over SSL,也就是让HTTP连接建立在SSL安全连接之上. SSL使用证书来创建安全连接.有两种验证模 ...