在网页中为了控制.unity文件的大小,加速载入速度,可以把系统用到的资源制作成Assestbundles,根据需要进行动态的加载和卸载。具体作法:
1、使用脚本重新定义系统菜单,添加一个制作Assetbunles的菜单命令:
// C# Example
// Builds an asset bundle from the selected objects in the project view.
// Once compiled go to "Menu" -> "Assets" and select one of the choices
// to build the Asset Bundle
using UnityEngine;
using UnityEditor;
public class ExportAssetBundles {
[MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")]
static void ExportResource () {
// Bring up save panel
string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0) {
// Build the resource file from the active selection.
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
Selection.objects = selection;
}
}
[MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")]
static void ExportResourceNoTrack () {
// Bring up save panel
string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0) {
// Build the resource file from the active selection.
BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path);
}
}
}
以上脚本按类命名后放置在工程文件夹内Assets目录内的Edit文件夹内(如没有,自行新建)。这时如脚本描述的在菜单栏内的Assets下会出现Build AssetBundle From Selection的两个菜单,选中需要制作Assetbunles的资源生成即可。
2、使用www按需载入Assetbundle,举例如下
function Start () {
var url = "file:///D:/temp/XXX.unity3d";
StartCoroutine(LoadAsset(url));
}
function LoadAsset (url : String) {
var www : WWW = new WWW (url);
yield www;
var present : GameObject;
present = GameObject.Find("present");
if( present != null )
Destroy(present);
present = Instantiate(www.assetBundle.mainAsset);
present.name = "present"; //暂时把名字叫做“present”
}
相关推荐
Unity3D制作并使用Assetbundles方法 Posted on 2013年07月16日 by U3d / Unity3D脚本/插件 /被围观 35 次
unity3d打包工具AssetBundles-Browser-master
Unity3D教程:AssetBundles2
Unity3D制作逼真LED滚动字幕效果 说明:https://blog.csdn.net/qq_33789001/article/details/112678275
Unity 3D脚本编程 使用C#语言开发跨平台游戏 陈嘉栋 著 目录 第1 章 Hello Unity 3D 1 第2 章 Mono 所搭建的脚本核心基础22 第3 章 Unity 3D 脚本语言的类型系统58 第4 章 Unity 3D 中常用的数据结构99 第5 章 在...
利用unity3d这款游戏制作简单的贪吃蛇小游戏,喜欢的可以下载看下,代码完整,注释友好,每行都有注释
unity3D大场景优化+unity3d模型制作规范.zip
Unity3d制作的简单拼图游戏 制作流程可以看我的博客:http://blog.csdn.net/cube454517408/article/details/7907247
常用6500汉字(txt) 可用于Unity3d制作TextMesh Pro字体资源,字体中包括有ASCII字符
Unity、3D、特效、刀光、卡通、RPG、VFX、战斗、战斗光影、Unity3D、动作特效、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、Unity3D、...
2、Unity3d中使用HttpUtility,如果直接在plugins中引入 System.Web.DLL的话,在对Unity3d项目打包的时候会报错,在U3D环境中,编译运行一切正常,但在打包发布(Build)为PC版本可执行文件时,却出现错误:...
由于unity3d 5.3以上的版本才有UGUI 的DrowDownList组件,其它版本没有。于是参照JS下拉列表构建思想,制作了该组件。已经打包成了资源包,压缩包内包含有效果图和代码部分说明。
Unity3d中三维制作规范.doc
用Unity3D制作的2D小游戏实例,内含可执行文件exe,可以直接玩,适合新手。 交作业的不二自选。 下载打开就能运行,个人运行环境是2019版本的Unity3D
Unity3d之截图方法,希望对有需要的人有所帮助。
Unity3D教程:两种方法连接MySql数据库 Posted on 2013年06月27日 by U3d / Unity3D 基础教程/被围观 14 次 1、
在unity3d里可以打开usb连接的外置摄像头在unity3d里可以打开usb连接的外置摄像头在unity3d里可以打开usb连接的外置摄像头在unity3d里可以打开usb连接的外置摄像头在unity3d里可以打开usb连接的外置摄像头在unity3d...
unity3d材质资源包 大全 unity3d材质资源包 unity3d材质资源包 资源来源网络,如有侵权请通知删除。