• AssetDB
    • remote
    • library
  • explore
  • exploreLib
  • queryPathByUrl
  • queryUuidByUrl
  • queryPathByUuid
  • queryUrlByUuid
  • queryInfoByUuid
  • queryMetaInfoByUuid
  • deepQuery
  • queryAssets
  • import
  • create
  • move
  • delete
  • saveExists
  • createOrSave
  • saveMeta
  • refresh
  • Editor
  • assetdb

    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

    • url string
    • cb function The callback function
      • cb.path string

    queryUuidByUrl

    Get uuid by url

    Parameters

    • url string
    • cb function The callback function
      • cb.path string

    queryPathByUuid

    Get native file path by uuid

    Parameters

    • uuid string
    • cb function The callback function
      • cb.path string

    queryUrlByUuid

    Get asset url by uuid

    Parameters

    • uuid string
    • cb function The callback function
      • cb.url string

    queryInfoByUuid

    Get asset info by uuid

    Parameters

    • uuid string
    • cb function The callback function
      • cb.info object

    Examples

    1. ```js
    2. Editor.assetdb.queryInfoByUuid( uuid, function ( err, info ) {
    3. // info.path
    4. // info.url
    5. // info.type
    6. });
    7. ```

    queryMetaInfoByUuid

    Get meta info by uuid

    Parameters

    • uuid string
    • cb function The callback function
      • cb.info object

    Examples

    1. ```js
    2. Editor.assetdb.queryMetaInfoByUuid( uuid, function ( err, info ) {
    3. // info.assetPath
    4. // info.metaPath
    5. // info.assetMtime
    6. // info.metaMtime
    7. // info.json
    8. });
    9. ```

    deepQuery

    Query all assets from asset-db

    Parameters

    • cb function The callback function
      • cb.results array

    Examples

    1. ```js
    2. Editor.assetdb.deepQuery(function ( results ) {
    3. results.forEach(function ( result ) {
    4. // result.name
    5. // result.extname
    6. // result.uuid
    7. // result.type
    8. // result.children - the array of children result
    9. });
    10. });
    11. ```

    queryAssets

    Query assets by url pattern and asset-type

    Parameters

    • pattern string The url pattern
    • type string The asset type
    • cb function The callback function
      • cb.results array
    • url
    • assetType

    Examples

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

    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

    1. ```js
    2. Editor.assetdb.import( [
    3. '/file/to/import/01.png',
    4. '/file/to/import/02.png',
    5. '/file/to/import/03.png',
    6. ], 'db://assets/foobar' );
    7. ```

    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

    • url string
    • data string
    • cb function

    Examples

    1. ```js
    2. Editor.assetdb.create( 'db://assets/foo/bar/foobar.js', 'var foobar = 0;');
    3. ```

    move

    Move asset from src to dest
    The moved result will be sent through by ipc message asset-db:assets-moved

    Parameters

    • srcUrl string
    • destUrl string
    • showMessageBox

    Examples

    1. ```js
    2. Editor.assetdb.move( 'db://assets/foo/bar/foobar.js', 'db://assets/foo/bar/foobar02.js');
    3. ```

    delete

    Delete assets by url list
    The deleted results will be sent through by ipc message asset-db:assets-deleted

    Parameters

    • urls array

    Examples

    1. ```js
    2. Editor.assetdb.delete([
    3. 'db://assets/foo/bar/foobar.js',
    4. 'db://assets/foo/bar/foobar02.js',
    5. ]);
    6. ```

    saveExists

    Save specific asset by sending string data
    The saved results will be sent through by ipc message asset-db:asset-changed

    Parameters

    • url string
    • data string
    • cb function the callback function

    Examples

    1. ```js
    2. Editor.assetdb.saveExists( 'db://assets/foo/bar/foobar.js', 'var foobar = 0;');
    3. ```

    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

    • url string
    • data string
    • cb function the callback function

    Examples

    1. ```js
    2. Editor.assetdb.createOrSave( 'db://assets/foo/bar/foobar.js', 'var foobar = 0;');
    3. ```

    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

    • uuid string
    • metaJson string
    • cb function the callback function

    Examples

    1. ```js
    2. Editor.assetdb.saveMeta( meta.uuid, JSON.stringify(meta, null, 2));
    3. ```

    refresh

    Refresh the assets in url, and return the results

    Parameters

    • url string
    • cb function?

    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. ```

    Editor

    assetdb

    The AssetDB instance