A base class for all scripts attached to nodes. It exposes the Components lifetime functions, which the user can override and change.
To create a script and attach it to a node, create a header file somewhere like scripts/ExampleScript.hpp:
#pragma once
#include <cereal/types/polymorphic.hpp>
#include <cereal/archives/json.hpp>
class ExampleScript :
public Script
{
public:
template <class Archive>
void save(Archive &ar) const {};
template <class Archive>
void load(Archive &ar) {};
void initialize()
{
}
void update(float deltaTime)
{
}
};
Definition components.hpp:387
CEREAL_REGISTER_TYPE(Label)
CEREAL_REGISTER_POLYMORPHIC_RELATION(Component, Label)
And do this to add your script to a node:
#include "scripts/ExampleScript.hpp"
std::shared_ptr<Node> exampleNode = std::make_shared<Node>();
exampleNode->addComponent(std::make_shared<ExampleScript>());