diff --git a/src/editor/editor_asset.cpp b/src/editor/editor_asset.cpp new file mode 100644 index 0000000000..bdd6a7a31d --- /dev/null +++ b/src/editor/editor_asset.cpp @@ -0,0 +1,52 @@ +#include "editor_asset.h" + +namespace Lumix { + +EditorAssetPlugin::EditorAssetPlugin(const char* name, const char* ext, ResourceType type, StudioApp& app, IAllocator& allocator) + : AssetBrowser::Plugin(allocator) + , m_app(app) + , m_name(name) + , m_extension(ext) + , m_resource_type(type) +{ + AssetCompiler& compiler = app.getAssetCompiler(); + compiler.registerExtension(ext, type); + const char* extensions[] = { ext, nullptr }; + compiler.addPlugin(*this, extensions); + AssetBrowser& browser = app.getAssetBrowser(); + browser.addPlugin(*this); +} + +EditorAssetPlugin::~EditorAssetPlugin() { + m_app.getAssetBrowser().removePlugin(*this); + m_app.getAssetCompiler().removePlugin(*this); +} + +AssetBrowser::ResourceView& EditorAssetPlugin::createView(const Path& path, StudioApp& app) { + struct View : AssetBrowser::ResourceView { + View(const Path& path, ResourceType type, IAllocator& allocator) + : m_path(path) + , m_allocator(allocator) + , m_type(type) + {} + + const struct Path& getPath() override { return m_path; } + struct ResourceType getType() override { return m_type; } + bool isEmpty() override { return false; } + bool isReady() override { return true; } + bool isFailure() override { return false; } + u64 size() override { return 0; } + void destroy() override { LUMIX_DELETE(m_allocator, this); } + Resource* getResource() override { ASSERT(false); return nullptr; } + + IAllocator& m_allocator; + Path m_path; + ResourceType m_type; + }; + + IAllocator& allocator = app.getAllocator(); + View* view = LUMIX_NEW(allocator, View)(path, m_resource_type, allocator); + return *view; +} + +} \ No newline at end of file diff --git a/src/editor/editor_asset.h b/src/editor/editor_asset.h new file mode 100644 index 0000000000..487d223b14 --- /dev/null +++ b/src/editor/editor_asset.h @@ -0,0 +1,31 @@ +#include "editor/asset_browser.h" +#include "editor/asset_compiler.h" + +namespace Lumix { + +// use this if you want an editor-only asset to be visible in asset browser +// editor only assets do not inherit from Resource, e.g. particle system function +struct EditorAssetPlugin : AssetBrowser::Plugin, AssetCompiler::IPlugin { + EditorAssetPlugin(const char* name, const char* ext, ResourceType type, StudioApp& app, IAllocator& allocator); + ~EditorAssetPlugin(); + + bool compile(const Path& src) override { return true; } + bool canCreateResource() const override { return true; } + const char* getDefaultExtension() const override { return m_extension; } + + bool onGUI(Span resource) override { return false; } + const char* getName() const override { return m_name; } + ResourceType getResourceType() const override { return m_resource_type; } + AssetBrowser::ResourceView& createView(const Path& path, StudioApp& app) override; + + void deserialize(InputMemoryStream& blob) override { ASSERT(false); } + void serialize(OutputMemoryStream& blob) override {} + +protected: + StudioApp& m_app; + const char* m_extension; + const char* m_name; + ResourceType m_resource_type; +}; + +} \ No newline at end of file