AssetDB singleton class in main process, you can access the instance with Editor.assetdb
.
Return uuid by url. If uuid not found, it will return null.
Parameters
url
string
Returns string
Return uuid by file path. If uuid not found, it will return null.
Parameters
fspath
string
Returns string
Return file path by uuid. If file path not found, it will return null.
Parameters
uuid
string
Returns string
Return url by uuid. If url not found, it will return null.
Parameters
uuid
string
Returns string
Return url by file path. If file path not found, it will return null.
Parameters
fspath
string
Returns string
Return file path by url. If url not found, it will return null.
Parameters
url
string
Returns string
Check existance by url.
Parameters
url
string
Returns string
Check existance by uuid.
Parameters
uuid
string
Returns string
Check existance by path.
Parameters
fspath
string
Returns string
Check whether asset for a given url is a sub asset.
Parameters
url
string
Returns boolean
Check whether asset for a given uuid is a sub asset.
Parameters
uuid
string
Returns boolean
Check whether asset for a given path is a sub asset.
Parameters
fspath
string
Returns boolean
Check whether asset contains sub assets for a given url.
Parameters
url
string
Returns boolean
Check whether asset contains sub assets for a given uuid.
Parameters
uuid
string
Returns boolean
Check whether asset contains sub assets for a given path.
Parameters
path
stringfspath
Returns boolean
Return asset info by a given url.
Parameters
url
string
Returns object {uuid, path, url, type, isSubAsset}
Return asset info by a given uuid.
Parameters
uuid
string
Returns object {uuid, path, url, type, isSubAsset}
Return asset info by a given file path.
Parameters
fspath
string
Returns object {uuid, path, url, type, isSubAsset}
Return all sub assets info by url if the url contains sub assets.
Parameters
url
string
Returns array [{uuid, path, url, type, isSubAsset}]
Return all sub assets info by uuid if the uuid contains sub assets.
Parameters
uuid
string
Returns array [{uuid, path, url, type, isSubAsset}]
Return all sub assets info by path if the path contains sub assets.
Parameters
fspath
string
Returns array [{uuid, path, url, type, isSubAsset}]
Return meta instance by a given url.
Parameters
url
string
Returns object
Return meta instance by a given uuid.
Parameters
uuid
string
Returns object
Return meta instance by a given path.
Parameters
fspath
string
Returns object
Return whether a given url is reference to a mount.
Parameters
url
string
Returns boolean
Return whether a given path is reference to a mount.
Parameters
fspath
string
Returns boolean
Return whether a given uuid is reference to a mount.
Parameters
uuid
string
Returns boolean
Return mount info by url.
Parameters
url
string
Returns object {path, name, type}
Return mount info by uuid.
Parameters
uuid
string
Returns object {path, name, type}
Return mount info by path.
Parameters
fspath
string
Returns object {path, name, type}
Mount a directory to assetdb, and give it a name. If you don't provide a name, it will mount to root.
Parameters
path
string file system path.mountPath
string the mount path (relative path).opts
object options.[cb]
function a callback function.
Examples
Editor.assetdb.mount('path/to/mount', 'assets', function (err) {
// mounted, do something ...
});
Attach the specified mount path.
Parameters
Examples
Editor.assetdb.attachMountPath('assets', function (err, results) {
// mount path attached, do something ...
// results are the assets created
});
Unattach the specified mount path.
Parameters
Examples
Editor.assetdb.unattachMountPath('assets', function (err, results) {
// mount path unattached, do something ...
// results are the assets deleted
});
Unmount by name.
Parameters
Examples
Editor.assetdb.unmount('assets', function (err) {
// unmounted, do something ...
});
Init assetdb, it will scan the mounted directories, and import unimported assets.
Parameters
[cb]
function
Examples
Editor.assetdb.init(function (err, results) {
// assets that imported during init
results.forEach(function (result) {
// result.uuid
// result.parentUuid
// result.url
// result.path
// result.type
});
});
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
}
});
});
deepQuery
Parameters
[cb]
function
Examples
Editor.assetdb.deepQuery(function (err, results) {
results.forEach(function (result) {
// result.name
// result.extname
// result.uuid
// result.type
// result.isSubAsset
// result.children - the array of children result
});
});
queryAssets
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
// result.isSubAsset
});
});
queryMetas
Parameters
Examples
Editor.assetdb.queryMetas('db://assets/**\/*', 'texture', function (err, results) {
results.forEach(function (meta) {
// the meta instance
});
});
move
Parameters
Examples
Editor.assetdb.move('db://assets/foo/foobar.png', 'db://assets/bar/foobar.png', function (err, results) {
results.forEach(function (result) {
// result.srcPath
// result.destPath
// result.uuid
// result.parentUuid
});
});
delete
Parameters
Examples
Editor.assetdb.delete(['db://assets/foo/bar.png', 'db://assets/foo/bar.plist'], function (err, results) {
results.forEach(function (result) {
// result.srcPath
// result.destPath
// result.uuid
// result.parentUuid
});
});
Create asset at url with data.
Parameters
Examples
Editor.assetdb.create('db://assets/foo/bar.js', data, function (err, results) {
results.forEach(function (result) {
// result.uuid
// result.parentUuid
// result.url
// result.path
// result.type
});
});
Save data to the exists asset at url.
Parameters
Examples
Editor.assetdb.saveExists('db://assets/foo/bar.js', data, function (err, meta) {
// do something
});
Import raw files to url.
Parameters
Examples
Editor.assetdb.import(['/User/user/foo.js', '/User/user/bar.js'], 'db://assets/foobar', function (err, results) {
results.forEach(function (result) {
// result.uuid
// result.parentUuid
// result.url
// result.path
// result.type
});
});
Overwrite the meta by loading it through uuid.
Parameters
Examples
Editor.assetdb.saveMeta(uuid, jsonString, function (err, meta) {
// do something
});
Exchange uuid for two assets.
Parameters
Clear imports.
Parameters
Examples
Editor.assetdb.clearImports('db://assets/foo/bar.js', function (err, results) {
results.forEach(function (result) {
// result.uuid
// result.url
// result.path
// result.type
});
});
Register meta type.
Parameters
Examples
Editor.assetdb.register('.png', false, PngMeta);
Unregister meta type.
Parameters
metaCtor
object
Examples
Editor.assetdb.unregister(PngMeta);
Get the relative path from mount path to the asset by fspath.
Parameters
fspath
string
Returns string the relative path from mount path to the asset.
Get the backup file path of asset file.
Parameters
filePath
string asset file path.