-
Creator 版本:2.4
-
目标平台: iOS
-
重现方式:真机必现, 浏览器正常
代码如下:
export class EventDispatcher {
public static cnt = 0;
public static _DISPATCHERS_DIC = {};
public static dispatchEvent(module, event) {
if (module) {
this.getInstance(module).dispatchEvent(event);
} else {
for (var k in EventDispatcher._DISPATCHERS_DIC) {
EventDispatcher._DISPATCHERS_DIC[k].dispatchEvent(event);
}
}
}
public static getInstance(module) {
cc.log(`event>> [${module}] inst(${EventDispatcher.cnt}) get >>>`);
let tm = EventDispatcher._DISPATCHERS_DIC[module];
if (!tm) {
////////// testing.
let icnt = 0;
for (let kv in EventDispatcher._DISPATCHERS_DIC) {
let estr = (EventDispatcher._DISPATCHERS_DIC[
kv
] as EventDispatcher).toString();
cc.log(
`event>> handle(${icnt++}): ${kv} dispatcher: ${estr}] `
);
}
//////////
tm = new EventListenerHandle(module);
EventDispatcher._DISPATCHERS_DIC[module] = tm;
EventDispatcher.cnt++;
}
cc.log(
`event>> [${module}] inst(${EventDispatcher.cnt}) get: ${tm.uuid}`
);
return tm;
}
}
另写一个类:
class XXComponent extends cc.Componen {
onLoad() {
EventListenerHandle.getInstance(“aaa”);
// 这里会得到一个值, EventDispatcher._DISPATCHERS_DIC 中增加一个值, 总数 1
}
onStart() {
EventListenerHandle.getInstance(“aaa”);
// 这里会得另一个值, EventDispatcher._DISPATCHERS_DIC 中增加一个值, 总数依然为 1
}
}
已经卡了3天了, 跪求各位大神救命