[add] EventBus使用 雙向溝通

This commit is contained in:
2022-08-01 17:12:37 +08:00
parent cf95786b9c
commit 7d4efe136f
9 changed files with 103927 additions and 134 deletions

View File

@@ -21,21 +21,28 @@ export default class HelloWorld extends cc.Component {
// LIFE-CYCLE CALLBACKS:
// protected onLoad() {}
protected onLoad() {
let self = this;
this.Label.string = this.Text;
window["eventBus"].on('SendContent', (content: string) => {
self.Label.string = content;
})
}
public onClickBtn() {
let url: string = window.location.search;
let URLscheme: any[] = [];
if (url.indexOf("?") !== -1) {
let str = url.substring(1);
let strs = str.split("&");
for (let i = 0; i < strs.length; i++) {
URLscheme[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
}
}
if (URLscheme["host"]) {
opener?.window.parent.postMessage({ data: "hello" }, URLscheme["host"]);
window.close();
}
window["eventBus"].emit("Alert", "hello");
// let url: string = window.location.search;
// let URLscheme: any[] = [];
// if (url.indexOf("?") !== -1) {
// let str = url.substring(1);
// let strs = str.split("&");
// for (let i = 0; i < strs.length; i++) {
// URLscheme[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
// }
// }
// if (URLscheme["host"]) {
// opener?.window.parent.postMessage({ data: "hello" }, URLscheme["host"]);
// window.close();
// }
}
}

File diff suppressed because it is too large Load Diff