7 template <
typename T,
typename... Args>
requires std::is_base_of_v<GameObject, T>
10 T*
object =
new T(std::move(
name), parent, std::forward<Args>(args)...);
12 if (parent->m_initialized)
13 static_cast<AbstractGameObject*
>(object)->
onSpawn();
17 template <
typename T,
typename... Args>
requires std::is_base_of_v<Component, T>
20 addComponent(
new T(
this, std::forward<Args>(args)...),
true);
23 template <
typename T>
requires std::is_base_of_v<Component, T>
29 template <
typename T>
requires std::is_base_of_v<Component, T>
35 template <
typename T>
requires std::is_base_of_v<Component, T>
39 for (
const auto* child : children())
47 auto child_components = child->componentsInChildren<T>();
48 std::copy(child_components.begin(), child_components.end(), std::back_inserter(
components));
53 template <
typename T>
requires std::is_base_of_v<Component, T>
56 const auto it = m_components.find(&T::classRtti());
57 if (it == m_components.cend())
59 return static_cast<T*
>(it->second.first);
62 template <
typename T>
requires std::is_base_of_v<Component, T>
65 for (
const auto* child : children())
74 template <
typename T>
requires std::is_base_of_v<Component, T>
77 return parent()->component<T>();
A GameObject is any object in the game. It contains a list of components that provides functionality ...
Definition GameObject.h:26
static T * Instantiate(std::string name, GameObject *parent, Args &&... args)
Instantiates a new GameObject.
Definition GameObject.h:8
const std::string & name() const
Gets the name of the GameObject.
Definition GameObject.cpp:58
virtual void onSpawn()
Method called when the GameObject is spawned in the scene.
Definition GameObject.h:178
void addComponent(Component *component, bool managed=false)
Adds a component to the GameObject.
Definition GameObject.cpp:68
void removeComponent()
Removes a component of the given type from the GameObject.
Definition GameObject.h:24
std::vector< T * > componentsInChildren() const
Gets a list of components of type T in any direct child of the GameObject.
Definition GameObject.h:36
bool hasComponent() const
Checks if the GameObject has a component of type T.
Definition GameObject.h:30
T * componentInParent() const
Gets a component of type T in any direct parent of the GameObject.
Definition GameObject.h:75
T * component() const
Gets a component of type T.
Definition GameObject.h:54
std::vector< Component * > components() const
Gets all the components for this GameObject.
Definition GameObject.cpp:87
T * componentInChildren() const
Gets a component of type T in any direct child of the GameObject.
Definition GameObject.h:63