How to programmatically access to assets when in `executeInEditMode`

I’m trying to write a script to import assets from DLtk export and I need some advice.

the idea is to use a data.json as entry point and parse it to build different nodes with attached images and polygon colliders so that the user can add its own script to every layer. You already do a similar thing with Tiled tile maps. I would like to have both the image and the colliders in the editor and not only at runtime, please keep this detail in mind.

Here’s an example of Node hierarchy:
image

Here’s the standard LDtk export structure
image

The missing point is to, programmatically, build a node and attach the corresponding .csv and .png files to the Node components.

I’ve looked into the documentation and I’ve only found AssetManager that can do the job but only (as far as I see) at runtime, which is not what I would like to have.

Do you have any advice to share ?

Thank you :slight_smile:

Which version of CocosCreator are you using?

3.7.x

Do you think is possible ? If not I’ll change strategy and will not try to create layers as Tilemaps does

You can use assetManager.loadAny({uuid:“AssetUUID”}, (err, res)=>{}) to load your asset in the editor. You can also use EDITOR to determine whether the current runtime environment is in the editor.

https://docs.cocos.com/creator/manual/en/asset/downloader-parser.html?h=loadany

https://docs.cocos.com/creator/manual/en/asset/options.html?h=loadany

2 Likes

Very handy thank you!

I think I need a bit of help, I’m only able to load by uuid so far, (no path or dir are working right now and I can’t really figure out why, the documentation doesn’t really help). Is there any way to programmatically get the list of assets in a given folder (giving that now I can get the assets itself with the loadAny method) ?

Here’s my idea (but I’m open to debate on it)

  1. user select a .json file :white_check_mark:
  2. we get the file content and parse to fill our needs :white_check_mark:
  3. we get the path to that .json file :x:
  4. we get filenames or uuids for every file in the same folder of our .json file :x:
  5. we can use loadAny to get the other assets :white_check_mark:

Here’s a typical structure of that folder
image

I’m not really sure about this strategy and I can’t see so far examples in the forum or in the doc.

Any suggestion ?