最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Iterating Assets in an Incisor project? - Stack Overflow

programmeradmin2浏览0评论

Is it possible to iterate through the assets in the Assets folder within an Incisor project?

I need to access asset files from within my code and would like to iterate over the assets in the Assets folder. Additionally, I want to manipulate these assets at runtime. Is there a way to achieve this?

Is it possible to iterate through the assets in the Assets folder within an Incisor project?

I need to access asset files from within my code and would like to iterate over the assets in the Assets folder. Additionally, I want to manipulate these assets at runtime. Is there a way to achieve this?

Share Improve this question asked Feb 14 at 21:17 Matt CMatt C 853 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

There are a couple of approaches depending on your needs for accessing and manipulating file data in your project.

1. Using nc.fileIO.getDirectoryContents to list files and directories:

You can retrieve a list of files and directories within the "Assets" directory using the nc.fileIO.getDirectoryContents function:

class ProjectMain {
  async init() {
    try {
      let directoryContentsList = await nc.fileIO.getDirectoryContents("Assets");
      console.log(directoryContentsList);
    } catch (error) {
      console.error('Error fetching directory contents:', error);
    }
  }
}

Key points to remember:

Asynchronous behavior: Most fileIO functions require await as they are asynchronous.

Project restrictions: fileIO is only available in un-published projects.

Usage in extensions: fileIO can also be used in extensions scripting, making it helpful for asset manipulation.

2. Accessing runtime assets via Incisor dictionaries:

Instead of working with files directly, you can iterate through runtime asset dictionaries in Incisor to view or manipulate assets. These dictionaries contain the actual assets used at runtime, such as:

nc.graphicAssets

nc.textures

nc.geometries

nc.sounds

These can be helpful if you're more interested in accessing or modifying assets that are already loaded in the project.

发布评论

评论列表(0)

  1. 暂无评论