unity3d格式的导出与加载
http://blog.csdn.net/nateyang/article/details/7567831
1.导出。unity3d格式资源:
http://game.ceeger.com/Script/BuildPipeline/BuildPipeline.BuildAssetBundle.html
这里我稍微改了一点点~~~代码如下:
- using UnityEngine;
- using UnityEditor;
- using System.IO;
- public class BuildAssetBundlesFromDirectory {
- [@MenuItem("Asset/Build AssetBundles From Directory of Files")]
- static void ExportAssetBundles () {
- // Get the selected directory
- //获取选择的目录
- string path = AssetDatabase.GetAssetPath(Selection.activeObject);
- Debug.Log("Selected Folder: " + path);
- if (path.Length != 0) {
- path = path.Replace("Assets/", "");
- string [] fileEntries = Directory.GetFiles(Application.dataPath+"/"+path);
- foreach(string fileName in fileEntries) {
- string filePath = fileName.Replace("\\","/");
- int index = filePath.LastIndexOf("/");
- filePath = filePath.Substring(index+1);
- Debug.Log("filePath:"+filePath);
- string localPath = "Assets/" + path+"/";
- if (index > 0)
- localPath += filePath;
- Object t = AssetDatabase.LoadMainAssetAtPath(localPath);
- if (t != null) {
- Debug.Log(t.name);
- string bundlePath = "Assets/" + path + "/" + t.name + ".unity3d";
- Debug.Log("Building bundle at: " + bundlePath);
- // Build the resource file from the active selection.
- //从激活的选择编译资源文件
- BuildPipeline.BuildAssetBundle
- (t, null, bundlePath, BuildAssetBundleOptions.CompleteAssets);
- }
- }
- }
- }
- }
注意:string filePath = fileName.Replace("\\","/"); 把“\”转化成“/”。“Assets/path/.prefab”和“path\.prefab”
把以上代码的脚本放到一个文件夹里面,选中该文件夹,再点击菜单栏上的按钮"Asset/Build AssetBundles From Directory of Files",就成功转成unity3d格式了
2.加载.unity3d:
- function Start () {
- var www = new WWW ("file:///"+Application.dataPath+"/resourse/Cube.unity3d");
- yield www;
- Instantiate(www.assetBundle.mainAsset);
- }
注:Application.dataPath获取改程序的资源路径。
- function Start ()
- {
- var www = WWW.LoadFromCacheOrDownload("http://210.30.12.33:8080/YangChun/file/Cube.unity3d",5);
- yield www;
- if (www.error != null)
- {
- Debug.Log (www.error);
- return;
- }
- Instantiate(www.assetBundle.mainAsset);
- }
我试了一下用Resources类的方法还不能加载unity3d格式的文件。不过如果是本地加载的话直接加载prefab就可以了,用不着用unity3d格式了。貌似
- LoadFromCacheOrDownload方法只能加载.unity3d格式文件,我用Tomcat服务器小测了一下,可以达到缓存的效果。
3.加载场景的话:
先把场景转化成unity3d格式的。
注:以下代码的脚本必须放在Editor文件夹下(如果没有改文件,新建一个就行),BuildTarget注意哈,转化成不同的平台~~~BuildTarget.Andrdoid
- <pre name="code" class="java">@MenuItem ("Build/BuildWebplayerStreamed")
- static function MyBuild(){
- var levels : String[] = ["Assets/yaya.unity"];
- BuildPipeline.BuildStreamedSceneAssetBundle( levels, "yaya.unity3d", BuildTarget.WebPlayer);//BuildTarget.Andrdoid
- }
- </pre>或者
- <pre></pre>
- <pre name="code" class="java" style="background-color: rgb(255, 255, 255); "><pre name="code" class="java">@MenuItem ("Build/BuildWebplayerStreamed")
- static function MyBuild(){
- BuildPipeline.BuildPlayer(["Assets/main.unity"],"VR.unity3d",BuildTarget.WebPlayer, BuildOptions.BuildAdditionalStreamedScenes);
- }</pre><br>
- <br>
- <br>
- <pre></pre>
- <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 () {
- // Download compressed scene. If version 5 of the file named "Streamed-Level1.unity3d" was previously downloaded and cached.
- // Then Unity will completely skip the download and load the decompressed scene directly from disk.
- //下载压缩的场景。如果名为Streamed-Level1.unity3d的文件版本为5,预先下载并缓存。
- //然后Unity将完全跳过下载并直接从磁盘加载解压的场景。
- var download = WWW.LoadFromCacheOrDownload ("http://210.30.12.16:8080/chunge/yaya.unity3d", 5);
- yield download;
- // Handle error
- if (download.error != null)
- {
- Debug.LogError(download.error);
- return;
- }
- // In order to make the scene available from LoadLevel, we have to load the asset bundle.
- // The AssetBundle class also lets you force unload all assets and file storage once it is no longer needed.
- //为了使场景LoadLevel可用,必须加载资源包
- //AssetBundle类,还可以强制卸载所有的资源和文件存储,一旦不再需要。
- var bundle = download.assetBundle;
- // Load the level we have just downloaded
- //加载刚才下载的关卡
- Application.LoadLevel ("yaya");//这里面的“yaya”是指“Assets/yaya.unity”而不是指“yaya.unity3d”
- }</pre><br><br></pre>
- <br>
- <br>
- <br>
- <p></p>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- </pre>
unity3d格式的导出与加载的更多相关文章
- Unity3d Web3d资源的动态加载
Unity3d Web3d资源的动态加载 @灰太龙 参考了宣雨松的博客,原文出处http://www.xuanyusong.com/archives/2405,如果涉及到侵权,请通知我! Unity3 ...
- unity3d进行脚本资源打包加载
原地址:http://www.cnblogs.com/hisiqi/p/3204752.html 本文记录如何通过unity3d进行脚本资源打包加载 1.创建TestDll.cs文件 public c ...
- 【Unity3D】Unity3D之 Resources.Load 动态加载资源
[Unity3D]Unity3D之 Resources.Load 动态加载资源 1.Resources.Load:使用这种方式加载资源,首先需要下Asset目录下创建一个名为Resources的文件夹 ...
- KEngine:Unity3D资源的打包、加载、调试监控
资源模块做什么? 资源模块——ResourceModule,是KEngine中最核心的模块,其他模块基本或多或少的对它有依赖,它主要的功能是:资源打包.路径定义.资源管理.资源调试. 资源模块对Uni ...
- unity3d 加密资源并缓存加载
原地址:http://www.cnblogs.com/88999660/archive/2013/04/10/3011912.html 首先要鄙视下unity3d的文档编写人员极度不负责任,到发帖为止 ...
- C#用ckplayer.js播放 MP4格式视频实现 边加载边播放
MVC设计模式下 在View页面里面使用ckplayer.js 加载视频 ,在MP4格式视频上传之后 我发现某些视频可以边加载边播放 但是有一些又不行,找了下原因是因为视频的元数据信息在第一帧的时候就 ...
- (转)unity3d加密资源并缓存加载
http://www.haogongju.net/art/1931680 首先要鄙视下unity3d的文档编写人员极度不负责任,到发帖为止依然没有更新正确的示例代码. view source pr ...
- Unity3D AssetBundle的打包与加载
在Unity项目开发过程中,当要做热更新时常常使用一个叫做AssetBundle的东西,这里做一点个人的学习记录 步骤1: 设置打包标签:具体步骤----进入Unity,选择某一资源然后看右下角,在那 ...
- Unity3D在移动平台下加载AssetBundle导致Shader效果不正确的问题
这个问题,主要还是在移动平台下开发导致的. 在编辑器里调试加载AB时会导致Shader效果不正确的原因,主要还是编辑器下加载以IOS或是ANDROID平台打包的AB它所使用的shader已经编译成对应 ...
随机推荐
- NIO使用Reactor模式遇到的问题
关于Reactor模式,不再多做介绍,推荐Doug Lea大神的教程:Java 可扩展的IO 本来在Reactor的构造方法中完成一系列操作是没有问题的: public class Reactor i ...
- Ajax使用进阶
关于Ajax的概念不再做解释了,我想通过三个小例子来让大家对Ajax有个清晰的认识.要学习它,必须从最基础最原始的方式开始认识,然后通过使用框架来提升效率,逐步认识它. 一.原生js版(注册的用户名是 ...
- 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 ...
- CentOS7和CentOS6的主要区别
了解一下就好 1. 文件系统的区别.CentOS6默认使用的是ext4的文件系统,而CentOS7使用的是xfs. 2. 硬盘默认调度算法不一样.CentOS6默认使用的是cfq,而CentOS7 ...
- Flask实战第66天:celery实现异步任务
Celery文档:http://docs.celeryproject.org Celery 通过消息进行通信,用专用的工作线程不断监视任务队列以执行新工作. Celery需要消息传输来发送和接收消息. ...
- Hive 空指针(NPE)异常
空指针NullPointerException 1 Hive之前的一些BUG [HIVE-9430] - NullPointerException on ALTER TABLE ADD PARTITI ...
- rxjava 视频
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha Rxjava-基础篇视频教程-Rxjava框架的使用-麦子学院 它的自我介绍,我们可以理 ...
- POJ2068 Nim 博弈论 dp
http://poj.org/problem?id=2068 博弈论的动态规划,依然是根据必胜点和必输点的定义,才明白过来博弈论的dp和sg函数差不多完全是两个概念(前者包含后者),sg函数只是mex ...
- poj 1348 Period(KMP)
Period Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- Nginx配置自签名的SSL证书(转载)
要保证Web浏览器到服务器的安全连接,HTTPS几乎是唯一选择.HTTPS其实就是HTTP over SSL,也就是让HTTP连接建立在SSL安全连接之上. SSL使用证书来创建安全连接.有两种验证模 ...