|
Capycore Engine
0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
|
Base class for all components that can be attached to GameObjects. More...
#include <component.h>
Public Member Functions | |
| Component () | |
| virtual | ~Component ()=default |
| bool | active () const noexcept |
| Checks if the component is active. | |
| Component & | active (bool value) noexcept |
| bool | marked_for_deletion () const noexcept |
| Activates the component. | |
| Component & | mark_for_deletion () noexcept |
| virtual void | update (float dt)=0 |
| virtual void | on_attach () |
| Called when the component is attached to a GameObject. | |
| virtual void | on_detach () |
| Called when the component is detached from a GameObject. | |
| virtual void | on_serialize (std::vector< uint8_t > &) const |
| Serializes the component's state into a byte array. | |
| virtual void | on_deserialize (const std::vector< uint8_t > &, size_t &) |
| Deserializes the component's state from a byte array. | |
| virtual std::string | type_name () const =0 |
| Provides a consistent type name for the component. | |
| const std::optional< std::reference_wrapper< GameObject > > & | parent () const noexcept |
| Gets the parent GameObject of this component. | |
| std::optional< std::reference_wrapper< GameObject > > & | parent () noexcept |
| Gets the parent GameObject of this component. | |
| Component & | parent (GameObject &parent) |
| Component & | parent (std::nullopt_t nullopt) |
| size_t | add_on_attach (const std::function< void(Component &)> &action) |
| Retrieves the type information of the component. | |
| void | remove_on_attach (size_t index) |
| size_t | add_on_detach (const std::function< void(Component &)> &action) |
| Adds an action to be performed when the component is attached. | |
| void | remove_on_detach (size_t index) |
Base class for all components that can be attached to GameObjects.
This is crucial for ensuring that component types can be accurately identified across different compilers and platforms, as relying on typeid(T).name() can lead to inconsistencies.
|
explicit |
|
virtualdefault |
|
noexcept |
Checks if the component is active.
|
noexcept |
| size_t Component::add_on_attach | ( | const std::function< void(Component &)> & | action | ) |
Retrieves the type information of the component.
| action | The action to be performed on attach. |
| size_t Component::add_on_detach | ( | const std::function< void(Component &)> & | action | ) |
Adds an action to be performed when the component is attached.
| action | The action to be performed on attach. |
|
noexcept |
|
noexcept |
Activates the component.
|
virtual |
Called when the component is attached to a GameObject.
Reimplemented in AudioSource, and BehaviorScript.
|
virtual |
Deserializes the component's state from a byte array.
| data | The byte array containing the serialized state. |
| offset | The current offset in the byte array from which to start reading. This offset will be updated as bytes are read. |
Reimplemented in NetworkIdentity, BehaviorScript, and Rigidbody2D.
|
virtual |
Called when the component is detached from a GameObject.
Reimplemented in AudioSource, and BehaviorScript.
|
virtual |
Serializes the component's state into a byte array.
| out | A vector to which the serialized bytes will be appended. |
Reimplemented in NetworkIdentity, BehaviorScript, and Rigidbody2D.
|
noexcept |
Gets the parent GameObject of this component.
|
noexcept |
Gets the parent GameObject of this component.
| parent | The GameObject to set as the parent. |
| Component & Component::parent | ( | GameObject & | parent | ) |
| Component & Component::parent | ( | std::nullopt_t | nullopt | ) |
| void Component::remove_on_attach | ( | size_t | index | ) |
| void Component::remove_on_detach | ( | size_t | index | ) |
|
pure virtual |
Provides a consistent type name for the component.
Implemented in Renderable, AIController, NavigationGraph, NavigationNode, Pathfinding, Animator, AudioSource, BehaviorScript, BoxCollider2D, CircleCollider2D, Collider2D, NetworkIdentity, Rigidbody2D, Sprite, Image, and Text.
|
pure virtual |
Implemented in AIController, NavigationGraph, NavigationNode, Pathfinding, AudioSource, BehaviorScript, BoxCollider2D, CircleCollider2D, Collider2D, Rigidbody2D, Sprite, Image, Text, Animator, and NetworkIdentity.