The message system is used to communicate between all the different systems of the games. Its main advantage is to avoid creating dependencies between systems. It also avoid having to pass and handle references through the systems. The systems don't need to know each other anymore.
For example, during a fight, the player chooses an attack then ask to the ui system to show the attack name. To do so, the fight system sends a message “SHOW_ATTACK_NAME” with parameters. It doesn't know who will receive it or how it will be executed. The fight system doesn't care anyway. On the other side, the ui system connects to the “SHOW_ATTACK_NAME” message to receive them and handle them. The ui system doesn't know who sent the message nor why.
The message manager is a singleton. It is the entry point for everything that wants to use messages. It lets you Connect/Detach/Send messages:
The callback method to pass must have the following signature : void Callback(IMessage _msg); The IMessage parameter can then be casted to another message object specific to the message received.
You have two ways to define a message:
The message manager stores connection to messages using a map between MessageId and MessageSlot. A message slot contains an event and method to add/remove callbacks and execute the callbacks. IMessage classes contains a MessageId element. This is the id used when sending a message with the Send(IMessage _msg) method. It needs to be set in the constructor of objects.