Better API for binding inspector drawers and added the ability to add whole component drawers
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
#include "../ComponentsPanel/LightPanel.h"
|
||||
#include "../ComponentsPanel/MeshPanel.h"
|
||||
#include "../ComponentsPanel/CameraPanel.h"
|
||||
#include "../ComponentsPanel/BoxColliderPanel.h"
|
||||
#include "../ComponentsPanel/CapsuleColliderPanel.h"
|
||||
#include "../ComponentsPanel/CylinderColliderPanel.h"
|
||||
#include "../ComponentsPanel/MeshColliderPanel.h"
|
||||
@@ -29,7 +28,8 @@ namespace Nuake
|
||||
|
||||
class EditorSelectionPanel
|
||||
{
|
||||
using DrawFieldTypeFn = std::function<void(entt::meta_data&, entt::meta_any&)>;
|
||||
using DrawComponentTypeFn = std::function<void(Nuake::Entity& entity, entt::meta_any& componentInstance)>;
|
||||
using DrawFieldTypeFn = std::function<void(entt::meta_data& fieldMeta, entt::meta_any& componentInstance)>;
|
||||
|
||||
private:
|
||||
TransformPanel mTransformPanel;
|
||||
@@ -37,7 +37,6 @@ private:
|
||||
NetScriptPanel mNetScriptPanel;
|
||||
MeshPanel mMeshPanel;
|
||||
CameraPanel mCameraPanel;
|
||||
BoxColliderPanel mBoxColliderPanel;
|
||||
MeshColliderPanel mMeshColliderPanel;
|
||||
CapsuleColliderPanel mCapsuleColliderPanel;
|
||||
CylinderColliderPanel mCylinderColliderPanel;
|
||||
@@ -62,8 +61,30 @@ public:
|
||||
void DrawResource(Nuake::Resource resource);
|
||||
void DrawPrefabPanel(Ref<Nuake::Prefab> prefab);
|
||||
|
||||
template<class T, auto Func>
|
||||
void RegisterComponentDrawer()
|
||||
{
|
||||
const auto t = entt::type_id<T>();
|
||||
ComponentTypeDrawers[t.hash()] = std::bind(Func, std::placeholders::_1, std::placeholders::_2);
|
||||
}
|
||||
|
||||
template<class T, auto Func, class O>
|
||||
void RegisterComponentDrawer(O* o)
|
||||
{
|
||||
ComponentTypeDrawers[entt::type_id<T>().hash()] = std::bind(Func, o, std::placeholders::_1, std::placeholders::_2);
|
||||
}
|
||||
|
||||
template<class T, auto Func, class O>
|
||||
void RegisterTypeDrawer(O* o)
|
||||
{
|
||||
FieldTypeDrawers[entt::type_id<T>().hash()] = std::bind(Func, o, std::placeholders::_1, std::placeholders::_2);
|
||||
}
|
||||
|
||||
protected:
|
||||
// List of functions to call for each type that needs to be drawn
|
||||
// Drawing functions for each component (for writing very specific inspectors for specific components)
|
||||
std::unordered_map<entt::id_type, DrawComponentTypeFn> ComponentTypeDrawers;
|
||||
|
||||
// List of functions to call for each component field type that needs to be drawn
|
||||
std::unordered_map<entt::id_type, DrawFieldTypeFn> FieldTypeDrawers;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user