LockDiagram/library/imports/55/55403563-1a5a-4f2f-9eb8-82c762641837.js
2024-10-30 15:21:35 +08:00

52 lines
1.5 KiB
JavaScript

"use strict";
cc._RF.push(module, '55403VjGlpPL564gsdiZBg3', 'Notification');
// Script/module/Notification/Notification.ts
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Notifications = void 0;
//全局通知
var Notifications = {
_eventMap: [],
on: function (masgId, callback, target) {
if (this._eventMap[masgId] === undefined) {
this._eventMap[masgId] = [];
}
this._eventMap[masgId].push({ callback: callback, target: target });
},
emit: function (masgId, parameter) {
var array = this._eventMap[masgId];
if (array === undefined)
return;
for (var i = 0; i < array.length; i++) {
var element = array[i];
if (element)
element.callback.call(element.target, parameter);
}
},
off: function (masgId, callback) {
var array = this._eventMap[masgId];
if (array === undefined)
return;
for (var i = 0; i < array.length; i++) {
var element = array[i];
if (element && element.callback === callback) {
array[i] = undefined;
break;
}
}
},
offMasgId: function (masgId) {
this._eventMap[masgId] = undefined;
},
removeAllMsg: function () {
for (var k in this._eventMap) {
if (this._eventMap[k]) {
this.offMasgId(k);
}
}
}
};
exports.Notifications = Notifications;
cc._RF.pop();