52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'bc645/UI1FCCZN1kaSNle9o', 'Notification');
|
|
// Script/tool/Notification.ts
|
|
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Notification = void 0;
|
|
//全局通知
|
|
var Notification = {
|
|
_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.Notification = Notification;
|
|
|
|
cc._RF.pop(); |