Message system
The message system in the editor is a function expansion package of IPC (Interprocess Communication). This system bears the burden of communication and interaction in the entire editor.
Message interaction is divided into two situations:
- General message: Actively send a message to a function (extended)
- Broadcast message: After a certain function (extension) completes an operation, a notification is sent to everyone to inform that the operation has been completed
It can be understood as a kind of external api, for example, scene editor defines a message API .
When writing an extension, use this API to send messages:
At this time, a promise object will be returned. After await, the info object obtained is part of the data on the node actually queried. This message is similar to a remote API call.
Broadcast message is a kind of notification to the outside after the operation in a certain function is completed. Take the scene editor as an example.
It needs to be defined like this in the extension:
After that, whenever the scene is ready, broadcasting scene:ready will trigger the initData
method in the hello-world
extension.
Please use lowercase words and cannot contain special characters. Use - to connect between words.
Cannot contain special characters other than :. The format is packageName: actionName
.
The is added to prevent naming conflicts. In your own extension, you need to directly indicate which broadcast (action) of which extension is monitored when monitoring.
In this way, you can more intuitively understand the message processing flow of the extension in package.json
.
Editor.Message.send(pkgName, message, ...args)
The
send
method only sends a message, and does not wait for the return. If you do not need to return data and do not care whether the execution is complete, please use this method.Editor.Message.broadcast(
${pkgName}:${actionName}, ...args)
The method only sends, and sends it to all extensions that monitor the corresponding message.