AssetDB
urlToUuid
Return uuid by url. if uuid not found, it will return null.
Parameters
url
string
Returns
fspathToUuid
Return uuid by file path. if uuid not found, it will return null.
Parameters
fspath
string
Returns
uuidToFspath
Return file path by uuid. if file path not found, it will return null.
Parameters
uuid
string
Returns
uuidToUrl
Return url by uuid. if url not found, it will return null.
Parameters
uuid
string
Returns
fspathToUrl
Return url by file path. if file path not found, it will return null.
Parameters
fspath
string
Returns
urlToFspath
Return file path by url. if url not found, it will return null.
Parameters
url
string
Returns
exists
Check existance by url.
Parameters
url
string
Returns
existsByUuid
Check existance by uuid.
Parameters
uuid
string
Returns
existsByPath
Check existance by path.
Parameters
fspath
string
Returns
isSubAsset
Check whether asset for a given url is a sub asset.
Parameters
url
string
Returns
isSubAssetByUuid
Check whether asset for a given uuid is a sub asset.
Parameters
uuid
string
Returns
isSubAssetByPath
Check whether asset for a given path is a sub asset.
Parameters
fspath
string
Returns
containsSubAssets
Check whether asset contains sub assets for a given url.
Parameters
url
string
Returns
containsSubAssetsByUuid
Check whether asset contains sub assets for a given uuid.
Parameters
uuid
string
Returns
containsSubAssetsByPath
Check whether asset contains sub assets for a given path.
Parameters
path
stringfspath
Returns
assetInfo
Return asset info by a given url.
Parameters
url
string
Returns { uuid, path, url, type, isSubAsset }
assetInfoByUuid
Return asset info by a given uuid.
uuid
string
Returns { uuid, path, url, type, isSubAsset }
assetInfoByPath
Return asset info by a given file path.
Parameters
fspath
string
Returns { uuid, path, url, type, isSubAsset }
subAssetInfos
Return all sub assets info by url if the url contains sub assets.
Parameters
url
string
Returns [{ uuid, path, url, type, isSubAsset }]
subAssetInfosByUuid
Return all sub assets info by uuid if the uuid contains sub assets.
Parameters
uuid
string
Returns [{ uuid, path, url, type, isSubAsset }]
subAssetInfosByPath
Return all sub assets info by path if the path contains sub assets.
Parameters
fspath
string
Returns [{ uuid, path, url, type, isSubAsset }]
loadMeta
Return meta instance by a given url.
Parameters
url
string
Returns
loadMetaByUuid
Return meta instance by a given uuid.
Parameters
uuid
string
Returns
loadMetaByPath
Return meta instance by a given path.
Parameters
fspath
string
Returns
isMount
Return whether a given url is reference to a mount
Parameters
url
string
Returns
isMountByPath
Return whether a given path is reference to a mount
Parameters
fspath
string
Returns
isMountByUuid
Return whether a given uuid is reference to a mount
Parameters
uuid
string
Returns
mountInfo
Return mount info by url
Parameters
url
string
Returns { path, name, type }
mountInfoByUuid
Return mount info by uuid
Parameters
uuid
string
Returns { path, name, type }
mountInfoByPath
Return mount info by path
Parameters
fspath
string
Returns { path, name, type }
mount
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 pathmountPath
the mount path (relative path)opts
object optionsopts.hide
if the mount hide in assets browseropts.virtual
object if this is a virtual mount pointopts.icon
icon for the mount
cb
function? a callback function
Examples
attachMountPath
attach the specified mount path
Parameters
mountPath
the mount path (relative path)
Examples
```js
Editor.assetdb.attachMountPath('assets', function (err, results) {
// mount path attached, do something ...
// results are the assets created
});
```
unattachMountPath
unattach the specified mount path
Parameters
mountPath
string the mount path (relative path)cb
? a callback function
Examples
```js
Editor.assetdb.unattachMountPath('assets', function (err, results) {
// mount path unattached, do something ...
// results are the assets deleted
});
```
unmount
Parameters
mountPath
string the mount pathcb
?
Examples
```js
Editor.assetdb.unmount('assets', function (err) {
// unmounted, do something ...
});
```
init
Init assetdb, it will scan the mounted directories, and import unimported assets.
Parameters
cb
function?
Examples
```js
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
Refresh the assets in url, and return the results
Parameters
url
cb
function?
Examples
```js
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
deepQuery
Parameters
cb
?
Examples
queryAssets
queryAssets
Parameters
pattern
string The url patternassetTypes
( | array) The asset type(s)cb
? The callback functionurlPattern
Examples
```js
Editor.assetdb.queryAssets( 'db://assets/**\/*', 'texture', function ( err, results ) {
results.forEach(function ( result ) {
// result.url
// result.path
// result.uuid
// result.type
// result.isSubAsset
});
});
```
queryMetas
queryMetas
Parameters
pattern
string The url patterntype
The asset typecb
function? The callback functionurlPattern
assetType
Examples
```js
Editor.assetdb.queryAssets( 'db://assets/**\/*', 'texture', function ( err, results ) {
results.forEach(function ( meta ) {
// the meta instance
});
});
```
move
move
Parameters
destUrl
cb
function?
Examples
```js
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
delete
Parameters
urls
cb
function?
Examples
```js
Editor.assetdb.delete( [ 'db://assets/foo/bar.png', 'db://assets/foo/bar.plist' ], function ( err, results ) {
// result.srcPath
// result.destPath
// result.uuid
// result.parentUuid
});
});
```
create
Create asset at url with data
Parameters
url
data
stringcb
?
Examples
```js
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
});
});
```
saveExists
Save data to the exists asset at url
Parameters
Examples
import
Import raw files to url
Parameters
rawfiles
url
stringcb
?
Examples
```js
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
});
});
```
saveMeta
Overwrite the meta by loading it through uuid
Parameters
Examples
```js
Editor.assetdb.saveMeta( uuid, jsonString, function ( err, meta ) {
// do something
});
```
exchangeUuid
Exchange uuid for two assets
Parameters
urlA
urlB
stringcb
?
clearImports
Clear imports
Parameters
url
stringcb
?
Examples
```js
Editor.assetdb.clearImports( 'db://assets/foo/bar.js', function ( err, results ) {
results.forEach(function ( result ) {
// result.uuid
// result.url
// result.path
// result.type
});
});
```
register
Register meta type
Parameters
Examples
```js
Editor.assetdb.register( '.png', false, PngMeta );
```
unregister
Unregister meta type
Parameters
metaCtor
Examples
```js
Editor.assetdb.unregister( PngMeta );
```
getRelativePath
Get the relative path from mount path to the asset by fspath
Parameters
fspath
string
Returns the relative path from mount path to the asset
getAssetBackupPath
Parameters
filePath
string asset file path