Base class for defining logic that can be attached to Components, similar to Unity's MonoBehaviour.
More...
#include <behavior.h>
Base class for defining logic that can be attached to Components, similar to Unity's MonoBehaviour.
Behaviors provide a structured lifecycle for game logic:
A Behavior operates on the Component it is attached to and provides utility methods for accessing the GameObject, Transform, and other Components. See it as a gateway to implement game logic that interacts with the engine's objects.
- Note
- Users should derive from this class to implement custom behavior.
- Warning
- on_update() must be overridden.
Usage:
◆ Behavior()
◆ ~Behavior()
◆ attach()
Attaches this Behavior to a Component.
- Parameters
-
| component | The component this behavior should operate on. |
- Exceptions
-
| std::runtime_error | if already attached. |
◆ destroy() [1/3]
| void Behavior::destroy |
( |
| ) |
|
Destroy the parent game object.
◆ destroy() [2/3]
Destroy a specific component on the parent game object.
◆ destroy() [3/3]
Destroy a specific game object in the scene.
◆ disable()
◆ enable()
◆ enabled()
| bool Behavior::enabled |
( |
| ) |
const |
- Returns
- Whether the behavior is currently enabled.
◆ game_object()
- Returns
- Reference to the GameObject this Behavior operates on.
- Exceptions
-
| std::runtime_error | if not attached. |
◆ get_component()
template<typename T >
| std::optional< std::reference_wrapper< T > > Behavior::get_component |
( |
| ) |
|
|
inline |
Retrieves a component of type T attached to the same GameObject.
- Template Parameters
-
| T | The type of the component to retrieve. |
- Returns
- An optional reference to the component if found, std::nullopt otherwise.
- Exceptions
-
| std::runtime_error | if not attached. |
◆ get_component_from_children()
| std::optional< std::reference_wrapper< T > > Behavior::get_component_from_children |
( |
| ) |
|
|
inline |
Get a component of type T attached to this GameObject's children.
- Template Parameters
-
| T | The type of the component to get. |
- Returns
- An optional reference to the component if found, std::nullopt otherwise.
◆ get_component_in_parent()
| std::optional< std::reference_wrapper< T > > Behavior::get_component_in_parent |
( |
| ) |
|
|
inline |
Get a component of type T attached to this GameObject's parents.
- Template Parameters
-
| T | The type of the component to get. |
- Returns
- An optional reference to the component if found, std::nullopt otherwise.
◆ get_components()
| std::vector< std::reference_wrapper< T > > Behavior::get_components |
( |
| ) |
|
|
inline |
Retrieves all components of type T attached to the same GameObject.
- Template Parameters
-
| T | The type of the components to retrieve. |
- Returns
- A vector of references to the components found.
- Exceptions
-
| std::runtime_error | if not attached. |
◆ get_components_from_children()
| std::vector< std::reference_wrapper< T > > Behavior::get_components_from_children |
( |
| ) |
|
|
inline |
Get all components of type T attached to this GameObject's children.
- Template Parameters
-
| T | The type of the component to get. |
- Returns
- A vector of references to the components found.
◆ get_components_in_parent()
| std::vector< std::reference_wrapper< T > > Behavior::get_components_in_parent |
( |
| ) |
|
|
inline |
Get all components of type T attached to this GameObject's parents.
- Template Parameters
-
| T | The type of the component to get. |
- Returns
- A vector of references to the components found.
◆ on_awake()
◆ on_deserialize()
Deserializes the behavior's state from a byte array.
- Parameters
-
| 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. |
- Returns
- void
◆ on_destroy()
◆ on_serialize()
Serializes the behavior's state into a byte array.
- Parameters
-
| out | A vector to which the serialized bytes will be appended. |
- Returns
- void
◆ on_start()
◆ on_update()
Called once per frame.
- Parameters
-
| dt | Time delta since last frame. |
◆ transform()
The documentation for this class was generated from the following file: