Extending the Database (DB)
When we use the assets in the extension, we need to register the asset folder in the extension to the asset database, and publish the assets with the extension when it is released.
Through this article we will learn how to register a asset folder and use the assets in scripts.
Asset registration needs to be configured in contributions
using the asset-db
field, as follows.
In the above example, we have registered the assets
folder in the root directory of the extension test-package
to the asset database.
Writing Script Resources in Extensions
In order to use the cc
definitions, we need to copy the definition files from {project directory}\temp\declarations
to the extension root directory.
Since foo.ts
is only used as a asset and is not part of the extension source code, we need to exclude it by adding exclude
configuration to tsconfig.json
, otherwise we will get a compilation error.
Assets such as images, text, fonts, etc. can be placed directly in the directory.
Using Assets in Extensions
To reference an asset within a package as a drag-and-drop component, use it in the same way as the assets in assets
and internal
.
Import Script
You can simply reference a script file from the AssetDatabase as follows:
You don’t need to pay attention to whether a class comes from an extension package, the TypeScript development environment’s auto-completion feature will prompt the import directory, no need to worry.