找回密碼
 注冊帳號

掃一掃,訪問微社區

assetdatabase.addobjecttoasset 添加對象到資源

2014-12-31 18:11| 發布者: 楊炎| 查看: 2410| 評論: 0|原作者: 蠻牛|來自: unity3d腳本manual

摘要: assetdatabase.addobjecttoasset 添加對象到資源static functionaddobjecttoasset(objecttoadd:object,assetpath: string) : voiddescription描述adds objecttoadd to an existing asset at path.將objecttoadd這個 ...

assetdatabase.addobjecttoasset 添加對象資源

static functionaddobjecttoasset(objecttoadd:object,assetpath: string) : void

description描述

adds objecttoadd to an existing asset at path.

將objecttoadd這個對象添加到指定路徑上的現有資源。

please note that you should only add assets to '.asset' assets, imported models or texture assets for example will lose their data. all paths are relative to the project folder. like: "assets/mytextures/hello.png"

請注意,你應該添加資源到”.assets”目錄下的資源中,例如導入模型紋理將會丟失它們地數據。所有的路徑都是相對于工程目錄文件。 例如” assets/mytextures/hello.png”。

@menuitem("gameobject/creatematerial")

static function creatematerial () {

// create a simple material asset

//新建一個簡單的材質資源

var material = newmaterial(shader.find("specular"));

assetdatabase.createasset(material, "assets/mymaterial.mat");

// add an animation clip to it

//添加一個動畫剪輯到材質上

var animationclip = newanimationclip();

animationclip.name = "my clip";

assetdatabase.addobjecttoasset(animationclip, material);

// reimport the asset after adding an object.

//在新建一個對象后重新導入資源

// otherwise the change only shows up when saving the project

//否則這個更改只會在保存工程時才顯示

assetdatabase.importasset(assetdatabase.getassetpath(animationclip));

// print the path of the created asset

//打印新建的資源

debug.log(assetdatabase.getassetpath(material));

}

o static functionaddobjecttoasset(objecttoadd:object,assetobject: object) : void

description描述

adds objecttoadd to an existing asset identified by assetobject.

將objecttoadd這個對象添加到assertobject定義的資源上。

please note that you should only add assets to '.asset' files, imported models or texture assets for example will lose their data when reimporting or quitting unity.

請注意,你只能添加資源到”.asset”文件中,例如導入模型或紋理在重新導入或退出unity時將會丟失數據。

@menuitem("gameobject/creatematerial")

static function creatematerial () {

// create a simple material asset

//新建一個新的材質資源

var material = newmaterial(shader.find("specular"));

assetdatabase.createasset(material, "assets/mymaterial.mat");

// add an animation clip to it

//添加一個動畫剪輯到材質上

var animationclip = newanimationclip();

animationclip.name = "my clip";

assetdatabase.addobjecttoasset(animationclip, material);

// reimport the asset after adding an object.

//添加對象后重新導入資源

// otherwise the change only shows up when saving the project

//否則這個更改只會在保存工程時才顯示

assetdatabase.importasset(assetdatabase.getassetpath(animationclip));

// print the path of the created asset

//打印新建的資源

debug.log(assetdatabase.getassetpath(material));

}

相關閱讀

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