Operating System Simulator Plugin
3.5.1
Unreal Engine plugin that simulates an Operating System Environment
|
Represents a global messenger for sending messages to multiple listeners. More...
#include "GlobalMessenger.h"
Public Member Functions | |
~FGlobalMessenger () | |
void | BroadcastMessage (const FGameplayTag &FilterTag, UObject *Payload) |
Broadcasts a global message to all registered listeners. | |
void | AddListener (const UObject *NewListener, const FGameplayTag &FilterTag, const FGlobalMessageReceiveDelegate &Callback) |
Adds a listener to the global message system. | |
bool | RemoveListener (const UObject *TestObject) |
Removes a listener from the global message system. | |
void | ClearMappedDelegates () |
Clears all mapped delegates in the global messenger. | |
Represents a global messenger for sending messages to multiple listeners.
The FGlobalMessenger class allows broadcasting messages to multiple listeners and managing those listeners. Messages can be filtered using gameplay tags to control which listeners receive the message.
FGlobalMessenger::~FGlobalMessenger | ( | ) |
void FGlobalMessenger::AddListener | ( | const UObject * | NewListener, |
const FGameplayTag & | FilterTag, | ||
const FGlobalMessageReceiveDelegate & | Callback ) |
Adds a listener to the global message system.
This method adds a listener to the global message system by mapping it with the provided filter tag and callback. The listener will receive messages that match the filter tag when the messages are broadcasted using the BroadcastMessage method.
NewListener | The pointer to the object that will receive the global message. |
FilterTag | The tag that represents the message. Only listeners with matching tags will receive the message. |
Callback | The delegate function to be executed when the message is received. |
void FGlobalMessenger::BroadcastMessage | ( | const FGameplayTag & | FilterTag, |
UObject * | Payload ) |
Broadcasts a global message to all registered listeners.
This method iterates over all registered listeners and executes their corresponding callbacks. The callbacks are only executed if they are bound. If an unbound callback is encountered, a warning message is logged indicating that the owning object could be destroyed. It is recommended to call 'RemoveListener' on the object before destroying it to prevent this warning.
FilterTag | The tag used to filter the listeners. Only listeners with matching tags will receive the message. If the tag is not valid, all listeners will receive the message. |
Payload | The payload object to pass to the listeners. * |
void FGlobalMessenger::ClearMappedDelegates | ( | ) |
Clears all mapped delegates in the global messenger.
This method clears all mapped delegates in the global messenger. It empties the container of mapped delegates, effectively removing all listeners from the global message system. The cleared delegates will no longer receive any messages.
bool FGlobalMessenger::RemoveListener | ( | const UObject * | TestObject | ) |
Removes a listener from the global message system.
This method removes the listener from the global message system by finding and removing the associated delegate from the mapped delegates container. The listener will no longer receive messages matching its filter tag. It is recommended to call this method before destroying the object to prevent warnings.
TestObject | The pointer to the object that needs to be removed as a listener. |