-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AssetBrowser::ResourceView*> 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; | ||
}; | ||
|
||
} |