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.
76 lines
2.5 KiB
76 lines
2.5 KiB
/*
|
|
* @Descripttion:
|
|
* @version: 1.0.0
|
|
* @Author: YeeChan
|
|
* @Date: 2020-07-09 18:54:41
|
|
*/
|
|
|
|
import { ryw_Event } from "../Event/EventEnum";
|
|
import { LogUtils } from "../Util/LogUtils";
|
|
|
|
/**
|
|
* 事件管理
|
|
*/
|
|
export default class EventMgr {
|
|
private static eventTarget_custom: cc.EventTarget = new cc.EventTarget();
|
|
|
|
|
|
/**
|
|
* 广播事件 通过事件名发送自定义事件
|
|
* @param name
|
|
* @param arg1
|
|
* @param arg2
|
|
* @param arg3
|
|
* @param arg4
|
|
* @param arg5
|
|
*/
|
|
public static emitEvent_custom(name: ryw_Event, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any) {
|
|
// LogUtils.info_custom("广播事件:" + name);
|
|
this.eventTarget_custom.emit(name + "", arg1, arg2, arg3, arg4, arg5);
|
|
}
|
|
/**
|
|
* 注册事件
|
|
* 注册事件目标的特定事件类型回调。这种类型的事件应该被 `emit` 触发。
|
|
* @param name
|
|
* @param callback
|
|
* @param target
|
|
*/
|
|
public static onEvent_custom(name: ryw_Event, callback: Function, target: any): void {
|
|
this.eventTarget_custom.on(name + "", callback, target);
|
|
}
|
|
|
|
/**
|
|
* 注册单次事件
|
|
* 注册事件目标的特定事件类型回调,回调会在第一时间被触发后删除自身。
|
|
* @param name
|
|
* @param callback
|
|
* @param target
|
|
*/
|
|
public static onceEvent_custom(name: ryw_Event, callback: (arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any) => void, target?: any): void {
|
|
this.eventTarget_custom.once(name + "", callback, target);
|
|
}
|
|
|
|
/**
|
|
* 移除事件注册
|
|
* 删除之前用同类型,回调,目标或 useCapture 注册的事件监听器,如果只传递 name,将会删除 name 类型的所有事件监听器。
|
|
* @param name
|
|
* @param callback
|
|
* @param target
|
|
*/
|
|
public static offEvent_custom(name: ryw_Event, callback?: Function, target?: any): void {
|
|
this.eventTarget_custom.off(name + "", callback, target);
|
|
}
|
|
|
|
/**
|
|
* 删除当前EventTarget指定目标(target 参数)注册的所有事件监听器。
|
|
这个函数无法删除当前 EventTarget 的所有事件监听器,也无法删除 target 参数所注册的所有事件监听器。
|
|
这个函数只能删除 target 参数在当前 EventTarget 上注册的所有事件监听器。
|
|
* @param target
|
|
*/
|
|
public static offTargetEvent_custom(target: any): void {
|
|
this.eventTarget_custom.targetOff(target);
|
|
}
|
|
|
|
|
|
|
|
} |