当前位置:网站首页>【oops-framework】全局事件
【oops-framework】全局事件
2022-07-21 21:18:00 【dgflash_game】
功能说明
OopsFramework-全局事件管理主要在设计上降低对象之间的耦合问题,避免相互调用API导致对象强依赖,从而在项目中后期需求变更或扩展时,增加维护成本。
使用说明
注册持续监听的全局事件
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;
}
}
}
边栏推荐
- [Bi design project recommendation] those interesting Bi design projects that seniors have done - Bi design project sharing (MCU embedded Internet of things STM32)
- FPGA——SPI总线控制flash(1)(含代码)
- Flutter实战-自定义键盘(三)
- FPGA - SPI bus control flash (1) (including code)
- 数据库索引的缺点
- GaitSet源代码解读(三)
- Hcip day 5
- [hero planet July training leetcode problem solving daily] 21st pile
- 【快速上手教程4】疯壳·开源编队无人机-OPENMV 脚本烧写
- 30.【静态数据成员】
猜你喜欢
National technology n32g452 debugging interface multiplexing function JTDI jtdo jntrst
Advantages of vr virtual simulation teaching software for cable fault monitoring
Redis是如何实现点赞、取消点赞的?(荣耀典藏版)
30.【静态数据成员】
数据库索引对写入操作的影响
师傅教你~LNMP源码搭建
EN 1504-5 products for protection and repair of concrete structures concrete spraying - CE certification
[how to optimize her] teach you how to locate unreasonable SQL? And optimize her~~~
盘一盘接口测试的那些痛点,你现在会解决了吗
EN 1504-4: structural bonding of concrete structure products - CE certification
随机推荐
【机器学习的数学01】可数集与不可数集
Master teaches you how to build LNMP source code
Research on mobile terminal location privacy protection for ocean view monitoring sensor network
Can you solve the pain points of interface testing now
计网-传输层
去中心化边缘渲染元宇宙协议Caduceus如何引爆Metaverse Summit 2022
师傅教你~LNMP源码搭建
Week 5 Linear Models for Classification (Part A)
An access scheme based on dynamic allocation of random access opportunity
31.【memcpy函数与strcpy函数】
Don't talk about the source code, talk about the practical application of bit operation
Interpretation of gaitset source code (III)
Legendary GOM engine setup tutorial
LeetCode:814. 二叉树剪枝【递归】
Day010 循环结构
[hero planet July training leetcode problem solving daily] 21st pile
Cadence学习之路:导入网表出错之引脚不对应
EN 1504-5 products for protection and repair of concrete structures concrete spraying - CE certification
工业厂区三维仿真可视化展示的应用
JVM parameter configuration description