Elevate Engine 1
Loading...
Searching...
No Matches
Component.h
Go to the documentation of this file.
1#pragma once
2
6#include <typeindex>
7
8#ifdef EE_ENGINE_BUILD
10#endif
11
12#define COMPONENT_LAYOUT(...) \
13 ComponentLayout GetLayout() const override { return ComponentLayout(GetName(), __VA_ARGS__);}
14
15namespace Elevate
16{
17 class GameObject;
18 class Scene;
19
20 using GameObjectComponentGetter = std::function<Component* (std::weak_ptr<GameObject>)>;
21 using GameObjectComponentFactory = std::function<Component* (std::weak_ptr<GameObject>)>;
22 using GameObjectComponentDestructor = std::function<void(std::weak_ptr<GameObject>)>;
23
24 class Component : public EEObject
25 {
26 friend class GameObject;
27 friend class Scene;
28
29 public:
30 std::function<bool()> RemoveFromGOFunc;
31
32 Component() = default;
33 virtual ~Component() = default;
34
35 // Reflection methods
36 virtual Component* Clone() = 0;
37 virtual void CopyFrom(Component* other) = 0;
40 virtual const void* GetEditorIconHandle() const { return nullptr; }
41 virtual std::type_index GetTypeIndex() const = 0;
42
43 inline void SetActive(bool newState) { m_IsActive = newState; }
44 inline bool IsActive() { return m_IsActive; }
45
46 // Method to override to define a layout in the editor, not mandatory but higly recommanded
47 // If no overrode, an empty layout is generated and nothing is shown in the inspector
48 virtual ComponentLayout GetLayout() const { return ComponentLayout(GetName(), {}); }
49
50 virtual bool RemoveFromGameObject() { return false; }
51
52 inline virtual std::string GetName() const {
53 return "Unknown Component Name";
54 //return ComponentRegistry::GetName(typeid(*this));
55 }
56 protected:
57 virtual void Init() {}
58 virtual void Destroy() {}
59 virtual void Update() {}
60
61 virtual void Render() {}
62 virtual void RenderInEditor() {} // Function that is only called if we are in the editor
63 virtual void RenderWhenSelected() {}
64
65 // Transform callbacks
66 virtual void OnSetPosition() {}
67 virtual void OnSetRotation() {}
68 virtual void OnSetScale() {}
69
70 virtual void OnNotify(Event& event) {}
71
72 public:
74 protected:
75 bool m_IsActive = true;
76 };
77}
virtual void RenderWhenSelected()
Definition Component.h:63
virtual void RenderInEditor()
Definition Component.h:62
virtual Component * Clone()=0
virtual void OnNotify(Event &event)
Definition Component.h:70
virtual GameObjectComponentDestructor GetDestructor() const =0
GameObject * gameObject
Definition Component.h:73
virtual void OnSetPosition()
Definition Component.h:66
virtual std::string GetName() const
Definition Component.h:52
virtual void CopyFrom(Component *other)=0
virtual ComponentLayout GetLayout() const
Definition Component.h:48
virtual void Init()
Definition Component.h:57
virtual void OnSetScale()
Definition Component.h:68
virtual std::type_index GetTypeIndex() const =0
virtual void Update()
Definition Component.h:59
virtual const void * GetEditorIconHandle() const
Definition Component.h:40
virtual GameObjectComponentFactory GetFactory() const =0
std::function< bool()> RemoveFromGOFunc
Definition Component.h:30
virtual void Destroy()
Definition Component.h:58
virtual void Render()
Definition Component.h:61
virtual void OnSetRotation()
Definition Component.h:67
virtual bool RemoveFromGameObject()
Definition Component.h:50
void SetActive(bool newState)
Definition Component.h:43
virtual ~Component()=default
std::function< Component *(std::weak_ptr< GameObject >)> GameObjectComponentFactory
Definition Component.h:21
std::function< Component *(std::weak_ptr< GameObject >)> GameObjectComponentGetter
Definition Component.h:20
std::function< void(std::weak_ptr< GameObject >)> GameObjectComponentDestructor
Definition Component.h:22