找回密碼
 注冊帳號

掃一掃,訪問微社區

buildpipeline.buildassetbundle 編譯資源包

2015-1-3 21:57| 發布者: 楊炎| 查看: 3118| 評論: 0|原作者: 蠻牛|來自: unity3d腳本manual

摘要: buildpipeline.buildassetbundle 編譯資源包static functionbuildassetbundle(mainasset:object,assets:object,pathname: string,options:buildassetbundleoptions=buildassetbundleoptions.collectdependencies|bui ...

buildpipeline.buildassetbundle" target="_blank" class="relatedlink">assetbundle 編譯資源

static functionbuildassetbundle(mainasset:object,assets:object[],pathname: string,options:buildassetbundleoptions=buildassetbundleoptions.collectdependencies|buildassetbundleoptions.completeassets,targetplatform:buildtarget=buildtarget.webplayer) : bool

description描述

builds an asset bundle (unity pro only).

生成一個資源包(僅用于unity pro)。

creates a compressed unity3d file that contains a collection of assets. assetbundles can contain any asset found in the project folder. this lets you stream resource data of any type, fully setup prefabs, textures, meshes, animations, any type of asset shown in the project window. mainasset lets you specify a specific object that can be conveniently retrieved usingassetbundle.mainasset. the compressed asset bundle file will be saved at pathname. options allows you to automatically include dependencies or always include complete assets instead of just the exact referenced objects. all paths are relative to the project folder. like: "assets/mytextures/hello.png"

創建一個壓縮的unity3d文件,包含資源的集合。資源包可以包含任何項目文件中的資源。這可以讓你流任何類型的資源數據,全部的預置設置,紋理,網格,動畫等顯示在項目窗口中的任意類型。mainasset讓你指定一個特定對象,可以方便的使用assetbundle.mainasset檢索。壓縮的資源包文件將保持在pathname。options允許您自動包括依賴關系或總是包含完整的資源,而不只是準確引用的對象。所有路徑相對于項目文件夾。像: "assets/mytextures/hello.png"

參見:assetbundle類,www.assetbundle.

// c# example

// builds an asset bundle from the selected folder in the project view.

// bare in mind that this script doesnt track dependencies nor is recursive

//在項目視圖從選擇的文件夾生成資源包

//記住,這個腳本不跟蹤依賴關系,也不是遞歸

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);

debug.log(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);

}

}

}

}

}

相關閱讀

文章點評
相關文章
女校游泳队彩金