全局消息管理
// 注册持续监听的全局事件export class RoleViewComp extends Component{ onLoad(){ // 监听全局事件 oops.message.on(GameEvent.GameServerConnected, this.onHandler, this); } protected onDestroy() { // 对象释放时取消注册的全局事件 oops.message.off(GameEvent.GameServerConnected, this.onHandler, this); } private onHandler(event: string, args: any) { switch (event) { case GameEvent.GameServerConnected: console.log("处理游戏服务器连接成功后的逻辑"); break; } }}// 注册只触发一次的全局事件export class RoleViewComp extends Component{ onLoad(){ // 监听一次事件,事件响应后,该监听自动移除 oops.message.once(GameEvent.GameServerConnected, this.onHandler, this); } private onHandler(event: string, args: any) { switch (event) { case GameEvent.GameServerConnected: console.log("处理游戏服务器连接成功后的逻辑"); break; } }}
Private
Static
Readonly
触发全局事件
Rest
移除全局事件
事件名
处理事件的侦听器函数
侦听函数绑定的作用域对象
注册全局事件
监听一次事件,事件响应后,该监听自动移除
事件触发回调方法
Generated using TypeDoc
全局消息管理
Example