How to make an extension add a custom component?

I have a TypeScript file with a class that inherits cc.Component. I want to put it inside an extension package and have it accessible in the editor (have an option to add it to a node etc.) once the package is added. How can I accomplish that?

I did not understand. You want the ability to export / import packages?

I want to put a TypeScript file I wrote in a package and have it accessible in the editor.

As an example, here’s an empty component class:

const {ccclass, property} = cc._decorator;

@ccclass
export default class TestScript extends cc.Component { }

I want to move this code into a package and still be able to add TestScript component in the editor.

I have tried just moving the script to the package folder like this:

Doing that will result in editor not seeing the script anymore since it’s not inside the assets directory.

If that’s not possible, then alternatively I would like to find a way to have the package move/copy a file from it’s own directory to the assets.

I really dont know. Have you tried to use the extension?
Extension -> Create a new Extension -> For all projects

Yup.‎‎‎‎‎‎

You can add “runtime-resource” property in package.json of your extension. image
image
then you will see your extension in asset panel。image

2 Likes

Thanks! That’s exactly what I was looking for.

Amazing!
Documentation link?

You can refer this. https://docs.cocos.com/creator/manual/en/extension/reference/package-json-reference.html

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.