AssetDB
AssetDB singleton class in renderer process, you can access the instance with Editor.assetdb
.
remote
The remote AssetDB instance of main process, same as Editor.remote.assetdb
.
library
The library path.
explore
Reveal given url in native file system.
Parameters
url
string
exploreLib
Reveal given url's library file in native file system.
Parameters
url
string
queryPathByUrl
Get native file path by url.
Parameters
queryUuidByUrl
Get uuid by url.
Parameters
queryPathByUuid
Get native file path by uuid.
Parameters
queryUrlByUuid
Get asset url by uuid.
Parameters
queryInfoByUuid
Get asset info by uuid.
Parameters
Examples
Editor.assetdb.queryInfoByUuid(uuid, function (err, info) {
// info.path
// info.url
// info.type
});
queryMetaInfoByUuid
Get meta info by uuid.
Parameters
Examples
Editor.assetdb.queryMetaInfoByUuid(uuid, function (err, info) {
// info.assetPath
// info.metaPath
// info.assetMtime
// info.metaMtime
// info.json
});
deepQuery
Query all assets from asset-db.
Parameters
Examples
Editor.assetdb.deepQuery(function (err, results) {
results.forEach(function (result) {
// result.name
// result.extname
// result.uuid
// result.type
// result.children - the array of children result
});
});
queryAssets
Query assets by url pattern and asset-type.
Parameters
pattern
string The url pattern.assetTypes
(string | array) The asset type(s).You can use the
Editor.assettype2name[cc.js.getClassName(asset)]
API to get the corresponding resource type. Theasset
in the API is the resource type you want to query, such ascc.SpriteFrame
,cc.Texture2D
.[cb]
function The callback function.cb.results
array
Examples
Editor.assetdb.queryAssets('db://assets/**\/*', 'texture', function (err, results) {
results.forEach(function (result) {
// result.url
// result.path
// result.uuid
// result.type
});
});
import
Import files outside asset-db to specific url folder. The import result will be sent through ipc message asset-db:assets-created
.
Parameters
rawfiles
array Rawfile path list.destUrl
string The url of dest folder.showProgress
boolean Show progress or not.[cb]
function The callbak function.
Examples
Editor.assetdb.import([
'/file/to/import/01.png',
'/file/to/import/02.png',
'/file/to/import/03.png',
], 'db://assets/foobar');
create
Create asset in specific url by sending string data to it. The created result will be sent through by ipc message asset-db:assets-created
.
Parameters
Examples
Editor.assetdb.create('db://assets/foo/bar/foobar.js', 'var foobar = 0;');
move
Move asset from src to dest. The moved result will be sent through by ipc message asset-db:assets-moved
.
Parameters
Examples
Editor.assetdb.move('db://assets/foo/bar/foobar.js', 'db://assets/foo/bar/foobar02.js');
delete
Delete assets by url list. The deleted results will be sent through by ipc message asset-db:assets-deleted
.
Parameters
urls
array
Examples
Editor.assetdb.delete([
'db://assets/foo/bar/foobar.js',
'db://assets/foo/bar/foobar02.js',
]);
saveExists
Save specific asset by sending string data. The saved results will be sent through by ipc message asset-db:asset-changed
.
Parameters
Examples
Editor.assetdb.saveExists('db://assets/foo/bar/foobar.js', 'var foobar = 0;');
createOrSave
Create or save assets by sending string data. If the url is already existed, it will be changed with new data. The behavior is same with method saveExists. Otherwise, a new asset will be created. The behavior is same with method create.
Parameters
Examples
Editor.assetdb.createOrSave('db://assets/foo/bar/foobar.js', 'var foobar = 0;');
saveMeta
Save specific meta by sending meta's json string. The saved results will be sent through by ipc message asset-db:asset-changed
.
Parameters
Examples
Editor.assetdb.saveMeta(meta.uuid, JSON.stringify(meta, null, 2));
refresh
Refresh the assets in url, and return the results.
Parameters
Examples
Editor.assetdb.refresh('db://assets/foo/bar/', function (err, results) {
// assets that imported during init
results.forEach(function (result) {
if (result.command === 'delete') {
// result.uuid
// result.url
// result.path
// result.type
} else if (result.command === 'change' || result.command === 'create') {
// result.uuid
// result.parentUuid
// result.url
// result.path
// result.type
} else if (result.command === 'uuid-change') {
// result.oldUuid
// result.uuid
// result.parentUuid
// result.url
// result.path
// result.type
}
});
});
Editor
assetdb
The AssetDB instance