| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import { Dictionary } from "./General";
- //事件管理类
- export class EventMng {
- private static _ins: EventMng;
- static get Ins(): EventMng {
- if (this._ins == null)
- this._ins = new EventMng();
- return this._ins;
- }
- /**
- * 注册事件
- * @param name 事件名
- * @param action 方法
- * @param target 执行回调的目标对象
- */
- static Register_Event(name: string, action: Function, target?: any) {
- if (!cc.systemEvent.hasEventListener(name)) {
- cc.systemEvent.on(name, action, target);
- } else {
- console.log("this event key has exist")
- }
- }
- /**
- * 删除事件
- * @param name 事件名
- * @param action 方法
- * @param target 执行回调的目标对象
- */
- static Remove_Event(name: string, action: Function, target?: any) {
- if (cc.systemEvent.hasEventListener(name)) {
- cc.systemEvent.off(name, action, target);
- } else {
- console.log("this event key has no exist");
- }
- }
- /**
- * 派发事件 执行事件
- * @param name 事件名
- * @param arg1 参数1
- * @param arg2 参数2
- * @param arg3 参数3
- * @param arg4 参数4
- * @param arg5 参数5
- */
- static Execute_Event(name: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any) {
- if (cc.systemEvent.hasEventListener(name)) {
- cc.systemEvent.emit(name, arg1, arg2, arg3, arg4, arg5);
- } else {
- console.log("this event key has no exist");
- }
- }
- }
|