SushiEngine::Simulation::IWorldEditor
add_script_component
virtual void add_script_component(EntityId id, const ScriptComponent &component)=0Parameters
| Name | Type | Description |
|---|---|---|
id | EntityId | The entity to update. |
component | const ScriptComponent & | The script component instance to attach. |
Description
Attaches a script component instance to id.
See also
engine/world/simulation/include/EDITOR.md
Example
void on_message(SushiEngine::Simulation::IWorldEditor& world,
SushiEngine::Simulation::EntityId self,
SushiEngine::Simulation::EntityId sender,
const std::string& name,
const SushiEngine::Simulation::ScriptField& payload) override
{
if (name == "StartSpinning")
{
SushiEngine::Simulation::ScriptField speed;
speed.name = "speed";
speed.kind = SushiEngine::Simulation::ScriptFieldKind::Float;
speed.number = payload.number;
SushiEngine::Simulation::ScriptComponent script;
script.type_name = "SpinningLight";
script.fields.push_back(speed);
world.add_script_component(self, script);
}
if (name == "StopSpinning")
world.remove_script_component(self, "SpinningLight");
}

