AssetDB

urlToUuid

Return uuid by url. if uuid not found, it will return null.

Parameters

Returns

fspathToUuid

Return uuid by file path. if uuid not found, it will return null.

Parameters

Returns

uuidToFspath

Return file path by uuid. if file path not found, it will return null.

Parameters

Returns

uuidToUrl

Return url by uuid. if url not found, it will return null.

Parameters

Returns

fspathToUrl

Return url by file path. if file path not found, it will return null.

Parameters

Returns

urlToFspath

Return file path by url. if url not found, it will return null.

Parameters

Returns

exists

Check existance by url.

Parameters

Returns

existsByUuid

Check existance by uuid.

Parameters

Returns

existsByPath

Check existance by path.

Parameters

Returns

isSubAsset

Check whether asset for a given url is a sub asset.

Parameters

Returns

isSubAssetByUuid

Check whether asset for a given uuid is a sub asset.

Parameters

Returns

isSubAssetByPath

Check whether asset for a given path is a sub asset.

Parameters

Returns

containsSubAssets

Check whether asset contains sub assets for a given url.

Parameters

Returns

containsSubAssetsByUuid

Check whether asset contains sub assets for a given uuid.

Parameters

Returns

containsSubAssetsByPath

Check whether asset contains sub assets for a given path.

Parameters

Returns

assetInfo

Return asset info by a given url.

Parameters

Returns { uuid, path, url, type, isSubAsset }

assetInfoByUuid

Return asset info by a given uuid.

Returns { uuid, path, url, type, isSubAsset }

assetInfoByPath

Return asset info by a given file path.

Parameters

Returns { uuid, path, url, type, isSubAsset }

subAssetInfos

Return all sub assets info by url if the url contains sub assets.

Parameters

Returns [{ uuid, path, url, type, isSubAsset }]

subAssetInfosByUuid

Return all sub assets info by uuid if the uuid contains sub assets.

Parameters

Returns [{ uuid, path, url, type, isSubAsset }]

subAssetInfosByPath

Return all sub assets info by path if the path contains sub assets.

Parameters

Returns [{ uuid, path, url, type, isSubAsset }]

loadMeta

Return meta instance by a given url.

Parameters

Returns

loadMetaByUuid

Return meta instance by a given uuid.

Parameters

Returns

loadMetaByPath

Return meta instance by a given path.

Parameters

Returns

isMount

Return whether a given url is reference to a mount

Parameters

Returns

isMountByPath

Return whether a given path is reference to a mount

Parameters

Returns

isMountByUuid

Return whether a given uuid is reference to a mount

Parameters

Returns

mountInfo

Return mount info by url

Parameters

Returns { path, name, type }

mountInfoByUuid

Return mount info by uuid

Parameters

Returns { path, name, type }

mountInfoByPath

Return mount info by path

Parameters

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 path
  • mountPath the mount path (relative path)
  • opts object options
    • opts.hide if the mount hide in assets browser
    • opts.virtual object if this is a virtual mount point
    • opts.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

  1. ```js
  2. Editor.assetdb.attachMountPath('assets', function (err, results) {
  3. // mount path attached, do something ...
  4. // results are the assets created
  5. });
  6. ```

unattachMountPath

unattach the specified mount path

Parameters

  • mountPath string the mount path (relative path)
  • cb ? a callback function

Examples

  1. ```js
  2. Editor.assetdb.unattachMountPath('assets', function (err, results) {
  3. // mount path unattached, do something ...
  4. // results are the assets deleted
  5. });
  6. ```

unmount

Parameters

  • mountPath string the mount path
  • cb ?

Examples

  1. ```js
  2. Editor.assetdb.unmount('assets', function (err) {
  3. // unmounted, do something ...
  4. });
  5. ```

init

Init assetdb, it will scan the mounted directories, and import unimported assets.

Parameters

Examples

  1. ```js
  2. Editor.assetdb.init(function (err, results) {
  3. // assets that imported during init
  4. results.forEach(function ( result ) {
  5. // result.uuid
  6. // result.parentUuid
  7. // result.url
  8. // result.path
  9. // result.type
  10. });
  11. });

refresh

Refresh the assets in url, and return the results

Parameters

Examples

  1. ```js
  2. Editor.assetdb.refresh('db://assets/foo/bar/', function (err, results) {
  3. // assets that imported during init
  4. results.forEach(function ( result ) {
  5. if ( result.command === 'delete' ) {
  6. // result.uuid
  7. // result.url
  8. // result.path
  9. // result.type
  10. } else if ( result.command === 'change' || result.command === 'create' ) {
  11. // result.uuid
  12. // result.parentUuid
  13. // result.url
  14. // result.path
  15. // result.type
  16. } else if ( result.command === 'uuid-change' ) {
  17. // result.oldUuid
  18. // result.uuid
  19. // result.parentUuid
  20. // result.url
  21. // result.path
  22. // result.type
  23. }
  24. });
  25. });
  26. ```

deepQuery

deepQuery

Parameters

  • cb ?

Examples

queryAssets

queryAssets

Parameters

  • pattern string The url pattern
  • assetTypes ( | array) The asset type(s)
  • cb ? The callback function
  • urlPattern

Examples

  1. ```js
  2. Editor.assetdb.queryAssets( 'db://assets/**\/*', 'texture', function ( err, results ) {
  3. results.forEach(function ( result ) {
  4. // result.url
  5. // result.path
  6. // result.uuid
  7. // result.type
  8. // result.isSubAsset
  9. });
  10. });
  11. ```

queryMetas

queryMetas

Parameters

  • pattern string The url pattern
  • type The asset type
  • cb function? The callback function
  • urlPattern
  • assetType

Examples

  1. ```js
  2. Editor.assetdb.queryAssets( 'db://assets/**\/*', 'texture', function ( err, results ) {
  3. results.forEach(function ( meta ) {
  4. // the meta instance
  5. });
  6. });
  7. ```

move

move

Parameters

Examples

  1. ```js
  2. Editor.assetdb.move( 'db://assets/foo/foobar.png', 'db://assets/bar/foobar.png', function ( err, results ) {
  3. results.forEach(function ( result ) {
  4. // result.srcPath
  5. // result.destPath
  6. // result.uuid
  7. // result.parentUuid
  8. });
  9. });
  10. ```

delete

delete

Parameters

Examples

  1. ```js
  2. Editor.assetdb.delete( [ 'db://assets/foo/bar.png', 'db://assets/foo/bar.plist' ], function ( err, results ) {
  3. // result.srcPath
  4. // result.destPath
  5. // result.uuid
  6. // result.parentUuid
  7. });
  8. });
  9. ```

create

Create asset at url with data

Parameters

Examples

  1. ```js
  2. Editor.assetdb.create( 'db://assets/foo/bar.js', data, function ( err, results ) {
  3. results.forEach(function ( result ) {
  4. // result.uuid
  5. // result.parentUuid
  6. // result.url
  7. // result.path
  8. // result.type
  9. });
  10. });
  11. ```

saveExists

Save data to the exists asset at url

Parameters

Examples

import

Import raw files to url

Parameters

Examples

  1. ```js
  2. Editor.assetdb.import( ['/User/user/foo.js', '/User/user/bar.js'], 'db://assets/foobar', function ( err, results ) {
  3. results.forEach(function ( result ) {
  4. // result.uuid
  5. // result.parentUuid
  6. // result.url
  7. // result.path
  8. // result.type
  9. });
  10. });
  11. ```

saveMeta

Overwrite the meta by loading it through uuid

Parameters

Examples

  1. ```js
  2. Editor.assetdb.saveMeta( uuid, jsonString, function ( err, meta ) {
  3. // do something
  4. });
  5. ```

exchangeUuid

Exchange uuid for two assets

Parameters

clearImports

Clear imports

Parameters

Examples

  1. ```js
  2. Editor.assetdb.clearImports( 'db://assets/foo/bar.js', function ( err, results ) {
  3. results.forEach(function ( result ) {
  4. // result.uuid
  5. // result.url
  6. // result.path
  7. // result.type
  8. });
  9. });
  10. ```

register

Register meta type

Parameters

  • extname string
  • folder Whether it’s a folder type
  • metaCtor object

Examples

  1. ```js
  2. Editor.assetdb.register( '.png', false, PngMeta );
  3. ```

unregister

Unregister meta type

Parameters

  • metaCtor

Examples

  1. ```js
  2. Editor.assetdb.unregister( PngMeta );
  3. ```

getRelativePath

Get the relative path from mount path to the asset by fspath

Parameters

Returns the relative path from mount path to the asset

getAssetBackupPath

Parameters

  • filePath string asset file path