Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
BehaviorScript Class Reference

Component that hosts a Behavior. More...

#include <behaviorscript.h>

Inheritance diagram for BehaviorScript:
[legend]

Public Member Functions

 BehaviorScript (std::unique_ptr< Behavior > behavior)
 
void on_attach () override
 Called when the component is attached to a GameObject.
 
void update (float dt) override
 
void on_detach () override
 Called when the component is detached from a GameObject.
 
Behaviorbehavior ()
 
bool enabled () const
 
BehaviorScriptenable ()
 
BehaviorScriptdisable ()
 
std::string type_name () const override
 Provides a consistent type name for the component.
 
virtual void on_serialize (std::vector< uint8_t > &out) const
 Serializes the component's state into a byte array.
 
virtual void on_deserialize (const std::vector< uint8_t > &data, size_t &offset)
 Deserializes the component's state from a byte array.
 
- Public Member Functions inherited from Component
 Component ()
 
virtual ~Component ()=default
 
bool active () const noexcept
 Checks if the component is active.
 
Componentactive (bool value) noexcept
 
bool marked_for_deletion () const noexcept
 Activates the component.
 
Componentmark_for_deletion () noexcept
 
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.
 
Componentparent (GameObject &parent)
 
Componentparent (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)
 

Detailed Description

Component that hosts a Behavior.

This class acts as a bridge between the Behavior system and the Component system, enabling Behaviors to be used as Components within the engine's architecture.

Note
Users typically do not interact with this class directly. Instead, they create custom Behaviors and attach them to GameObjects via Components.
See also
Behavior

Usage:

Constructor & Destructor Documentation

◆ BehaviorScript()

BehaviorScript::BehaviorScript ( std::unique_ptr< Behavior behavior)

Member Function Documentation

◆ behavior()

Behavior & BehaviorScript::behavior ( )

◆ disable()

BehaviorScript & BehaviorScript::disable ( )

◆ enable()

BehaviorScript & BehaviorScript::enable ( )

◆ enabled()

bool BehaviorScript::enabled ( ) const

◆ on_attach()

void BehaviorScript::on_attach ( )
overridevirtual

Called when the component is attached to a GameObject.

Reimplemented from Component.

◆ on_deserialize()

virtual void BehaviorScript::on_deserialize ( const std::vector< uint8_t > &  ,
size_t &   
)
inlinevirtual

Deserializes the component's state from a byte array.

Parameters
dataThe byte array containing the serialized state.
offsetThe current offset in the byte array from which to start reading. This offset will be updated as bytes are read.
Returns
void

Reimplemented from Component.

◆ on_detach()

void BehaviorScript::on_detach ( )
overridevirtual

Called when the component is detached from a GameObject.

Reimplemented from Component.

◆ on_serialize()

virtual void BehaviorScript::on_serialize ( std::vector< uint8_t > &  ) const
inlinevirtual

Serializes the component's state into a byte array.

Parameters
outA vector to which the serialized bytes will be appended.
Returns
A vector of bytes representing the serialized state of the component.

Reimplemented from Component.

◆ type_name()

std::string BehaviorScript::type_name ( ) const
overridevirtual

Provides a consistent type name for the component.

Returns
A string representing the type name of the component. @CAUTION: All derived components must implement this method to ensure consistent serialization across different compilers and platforms.

Implements Component.

◆ update()

void BehaviorScript::update ( float  dt)
overridevirtual

Implements Component.


The documentation for this class was generated from the following file: