| Description | Currently, the asset types supported by Studio are hard-coded. This makes it difficult to extend Studio with custom asset types, previews, icons, and file associations without modifying engine/editor code directly.
I propose introducing a new metadata type, StudioAsset, that allows assets to self-register their Studio integration data through reflection metadata.
class StudioAsset: public TypeMetaData
{
public:
StudioAsset() = default;
template <typename... Args>
StudioAsset* Extensions(Args... args)
{
_extensions.Clear();
_extensions.Reserve(sizeof...(Args));
(..., _extensions.PushBack(args));
return this;
}
StudioAsset* Icon(const Uri& font, uint32_t ch, const Color& color)
{
_font = font;
_ch = ch;
_color = color;
return this;
}
typedef Ptr<BaseComponent> (*PreviewFunc)(const Uri&);
StudioAsset* Preview(PreviewFunc preview)
{
_preview = preview;
return this;
}
ArrayRef<const char*> ExtensionsList() { return _extensions; }
const Uri& IconUri() { return _font; }
uint32_t IconChar() { return _ch; }
const Color& IconColor() { return _color; }
Ptr<BaseComponent> GenPreview(const Uri& uri) { return _preview(uri); }
private:
Vector<const char*> _extensions;
Uri _font;
uint32_t _ch;
Color _color;
PreviewFunc _preview;
};
Example Usage:
NS_IMPLEMENT_REFLECTION(Image)
{
NsMeta<StudioAsset>()
->Extensions(".png", ".jpg", ".dds")
->Icon(Noesis::Uri::Pack("Gui", "#Image-Icons"), 0xE934, Colors::Red())
->Preview([](const Uri& uri) -> Ptr<BaseComponent>
{
Ptr<Image> image = MakePtr<Image>();
image->SetSource(MakePtr<BitmapImage>(uri));
return image;
});
|
|---|