大侠
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

53 lines
1.4 KiB

/**
* 通知中心
* ***/
import { _decorator,EventTarget } from "cc";
import { PREVIEW } from "cc/env";
const {ccclass, property} = _decorator;
@ccclass
export class Model{
private RedNotice : EventTarget = null;
constructor() {
this.RedNotice = new EventTarget();
if (PREVIEW) {
window['RedNotice'] = RedNotice;
}
}
//开始监听通知
on<T extends Function>(type: string, listener:(...any: any[]) => void, target?: any, useCapture?: boolean){
this.RedNotice.on(type,listener,target,useCapture)
}
/**只执行一次 */
once<T extends Function>(type: string, callback: (arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any) => void, target?: any){
this.RedNotice.once(type,callback,target)
}
//开始出发消息
emit(key: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any){
this.RedNotice.emit(key,arg1,arg2,arg3,arg4,arg5)
}
//移除当前节点节点的所有事件
targetOff(node){
this.RedNotice.targetOff(node)
}
/**关闭单个 */
off(type: string, listener:(...any: any[]) => void, target?: any){
this.RedNotice.off(type,listener,target)
}
/** 判断有无事件 */
hasEventListener(type: string){
return this.RedNotice.hasEventListener(type)
}
}
export let RedNotice = new Model();