cocos-engine icon indicating copy to clipboard operation
cocos-engine copied to clipboard

[extensions] Support defining new recognized file formats - or resource files.

Open MrcSnm opened this issue 1 year ago • 0 comments

Use Case

There is a lot of times when one wishes to create a data-only component [i.e: not really a component]. This data-only component can be serialized/deserialized the same way as the editor does. It also uses the editor for user-friendly modification.

Problem Description

Workarounds:

  1. Create a prefab with the data-only component, then modify it. After that, copy the component data and paste it on where you're actually using. Problem: Your data can get out of sync and also this process take a lot more time to do.
  2. Have a prefab field, push this prefab, instantiate, get component and destroy the prefab. Problem: Lots of indirection and the check will only happen at runtime

Proposed Solution

Use package.json format for defining new supported formats: For example,

"contributions": {
        "assets": {
            "formats": {
                ".strip": "A strip format is somewhere you can define the data of type Strip"
            },

After that, one would be able to define an editor inspector extension for the .strip format:

"inspector": {
            "section": {
                "asset": {
                    "strip": "./dist/contributions/inspector/strip.js"
                }
            }
        },

How it works

No response

Alternatives Considered

Being able to serialize classes extending Asset. This idea comes mostly from Unity's scriptable objects and Godot Resource:

Godot: https://docs.godotengine.org/en/stable/tutorials/scripting/resources.html#creating-your-own-resources

Unity: https://docs.unity3d.com/Manual/class-ScriptableObject.html

Additional Information

No response

MrcSnm avatar Feb 11 '24 15:02 MrcSnm