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.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <memory>
7
27class BehaviorScript : public Component {
28 public:
29 BehaviorScript(std::unique_ptr<Behavior> behavior);
30
31 void on_attach() override;
32 void update(float dt) override;
33 void on_detach() override;
34
36
37 [[nodiscard]] bool enabled() const;
40
41 std::string type_name() const override;
42
43 virtual void on_serialize(std::vector<uint8_t>& out) const {
44 behavior_->on_serialize(out);
45 };
46 virtual void on_deserialize(const std::vector<uint8_t>& data,
47 size_t& offset) {
48 behavior_->on_deserialize(data, offset);
49 };
50
51 private:
52 bool started_{false};
53 std::unique_ptr<Behavior> behavior_;
54};
Base class for defining logic that can be attached to Components, similar to Unity's MonoBehaviour.
Definition behavior.h:34
Component that hosts a Behavior.
Definition behaviorscript.h:27
Behavior & behavior()
virtual void on_deserialize(const std::vector< uint8_t > &data, size_t &offset)
Deserializes the component's state from a byte array.
Definition behaviorscript.h:46
std::string type_name() const override
Provides a consistent type name for the component.
void on_detach() override
Called when the component is detached from a GameObject.
virtual void on_serialize(std::vector< uint8_t > &out) const
Serializes the component's state into a byte array.
Definition behaviorscript.h:43
bool enabled() const
BehaviorScript & disable()
BehaviorScript(std::unique_ptr< Behavior > behavior)
void on_attach() override
Called when the component is attached to a GameObject.
BehaviorScript & enable()
void update(float dt) override
Base class for all components that can be attached to GameObjects.
Definition component.h:24