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
@MenuItem ("Build/BuildWebplayerStreamed")
static function MyBuild(){
var levels : String[] = ["Assets/yaya.unity"];
BuildPipeline.BuildStreamedSceneAssetBundle( levels, "yaya.unity3d", BuildTarget.WebPlayer);//BuildTarget.Andrdoid
}
或者
@MenuItem ("Build/BuildWebplayerStreamed")
static function MyBuild(){
BuildPipeline.BuildPlayer(["Assets/main.unity"],"VR.unity3d",BuildTarget.WebPlayer, BuildOptions.BuildAdditionalStreamedScenes);
}
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”
}
分享到:
相关推荐
Unity3d网络加载模型和导出unity3d格式文件
Unity3D教程:格式的导出与加载 Posted on 2013年06月19日 by U3d / Unity3D 基础教程/被围观 61 次 1.导出Unit
首先美工制作场景资源的3D建模,游戏设计人员把3D建模导进Unity3D,托托拽拽编辑场景,完成后把每个gameobject导出成XXX.unity3d格式的资
可以让unity动态加载本地或远程地址的GLTF/GLB格式的插件
建议先看说明:https://blog.csdn.net/qq_33789001/article/details/123716922 Unity3d 基于xlua热更新实现系列三:生成AB包导出并实现AB包动态加载源码
Unity3D教程:FBX如何内嵌纹理 Posted on 2013年02月16日 by U3d / Unity3D 软件操作 /被围观 455 次 FBX打开
强大的unity3d集成Ink语言插件用于avg文字游戏 Ink Objects是一个简单的包,可以让对C#和Unity有基本理解的开发人员采用面向对象的方法编写广受喜爱的Ink语言。在Unity编辑器中构建对象库并将其导出到Ink中,就可以...
Unity3DTiles Unity3DTiles是开放格式的基于Unity的实现,用于流传输和渲染大型静态模型,例如由摄影测量管线生成的静态模型。 3D Tiles规范的好处在于,它允许一种通用渲染实现来支持使用许多不同数据结构(例如,...
内部包含unity2018.3.5版本unity工程、android3.5.3安卓工程和测试apk,本内容仅供学习参考,不能商业用途,后续会有文章讲解,有问题请留言
解决Unity发布WebGL无法正常浏览问题,下载Config文件,放到发布的目录中
一个用于渲染资产的Unity3D插件。 是机器学习驱动的工具,用于在3D空间中重建2D图像和视频。 有关Beta版的早期版本,请通过给我们 用法 使用将插件的最新版本下载为.unitypackage 打开包装后,您将按照以下顺序...
Unity AB包资源提取 框架查看
unity海南黎族大力神unity游戏(免积分下载),有按钮,背景音乐,游戏音效,有六个场景,游戏开始是菜单,菜单有游戏背景和游戏说明,这两个是采用文字逐个出现的效果演示,点击开始游戏进入游戏加载页面,加载到...
将Assets文件夹中的所有内容导出为.unitypackage文件。 如果您不需要Lua命令解析器,请在导出窗口中取消选中以下文件夹: Console / Addons / LuaCommandParser和Plugins 。 将.unitypackage文件导入到您的项目中...
在原生android项目中嵌入unity是一个十分普遍的需求,特别是当要在android App中加入一些原生android不易实现的功能,如加载比较复杂的3d模型,显示复杂的动画,开启摄像头实现AR功能(实现AR本身不难,难的是处理...
BVH Unity工具使您可以记录运动数据并将其从化身或骨架导出到BVH文件,以便可以使用Blender或其他程序对其进行编辑。 随附的动画加载组件使在运行时将BVH文件导入Unity成为可能。 建立 BVHRecorder组件通常应最后...
OpenBrushVR Open Brush是适用于Vive,Tango和Iphone的3D VR / AR绘画应用程序 它仍处于beta阶段,但进展遥遥无期,并且有一条明确的途径可以将其交付给秋季产品。 在此处查看一些视频。 安装说明:Tango和Vive应该...
回购,工具或回购所有者均未与Unity Technologies或其关联公司有任何关联,赞助或授权。 AssetStudio是用于探索,提取和导出资产和资产捆绑的工具。 特征 支持版本: 2.5-2020.2 支持资产类型: Texture2D :...
JPEG-LS,JPEG2000和RLE图像压缩(仅限于.NET Core,Xamarin,Mono和Unity平台) 支持非常大的数据集,并按需加载内容特定于平台的图像渲染JSON支持XML导出匿名化安装最简单的方法是从获取fo-dicom二进制文件。...
(全部撤销/重做、放大/缩小、迷你地图、多选、复制、复制/粘贴、JSON 导入/导出、群组、注释等) ● 图形、GameObject 和全局黑板变量,以创建可重复使用和以智能体为中心的参数行为。 ● 具有实例或静态属性和字段...