-
Notifications
You must be signed in to change notification settings - Fork 400
Signals
Signals can be used to connect events and functions - e.g. call a function when user clicks on a button.
To do this, simply add Core / Signal
component to an entity and set event and function to desired values.
All events on modules registered in reflection system (e.g. by using LUMIX_EVENT macro) can be used as a source.
All functions on modules registered in reflection system (e.g. by using LUMIX_FUNC macro) can be used as a destination.
Parameters in source and destination must match. Signal is assigned to an entity, i.e. the function is called only if event is triggered on registered entities. You can connect multiple signals to the same destination.
Let's assume you want to react to user clicking on a button. There's already an event for that GUIModule::buttonClicked(EntityRef e)
.
- In a module (e.g. your
GameModule
) create a functionvoid GameModule::connectClicked(EntityRef e)
- register the function in reflection system:
LUMIX_MODULE(GameModule, "myplugin").LUMIX_FUNC(connectClicked)
- create an entity with a gui button
- attach a signal component to the button entity
- in property grid set signal's event to
GUIModule::buttonClicked
and function toconnectClicked
- observe that
GameModule::connectClicked
is called every time users clicks on the button