显示Engine版本号

This commit is contained in:
xu_yanfeng
2025-01-12 17:57:02 +08:00
parent aba21c6f89
commit 8bff11cc10
10 changed files with 91 additions and 27 deletions

View File

@@ -18,4 +18,9 @@ export class InjectEvent {
const event = new CustomEvent(DocumentEvent.Inject2Content, { detail });
document.dispatchEvent(event);
}
sendEngineVersion(version: string) {
const detail = version;
const event = new CustomEvent(DocumentEvent.EngineVersion, { detail });
document.dispatchEvent(event);
}
}

View File

@@ -70,16 +70,47 @@ export class Inspector extends InjectEvent {
}
init() {
console.log(...this.terminal.init());
this.watchIsCocosGame();
}
private watchIsCocosGame() {
const timer = setInterval(() => {
const b = this._isCocosGame();
if (b) {
clearInterval(timer);
const version = this.getEngineVersion();
if (b && version) {
this.uploadEngineVersion(version);
}
}
}, 300);
}
private getEngineVersion() {
if (this._isCocosGame()) {
return cc.ENGINE_VERSION || "";
} else {
return "";
}
}
notifySupportGame(b: boolean) {
this.sendMsgToContent(Msg.ResponseSupport, { support: b, msg: "" } as ResponseSupportData);
const version = this.getEngineVersion();
this.sendMsgToContent(Msg.ResponseSupport, { support: b, msg: "", version } as ResponseSupportData);
}
/**
* 防止后台收到大量的Engine版本数据每次调试只上传一次
*/
private hasUploadEngineVersion = false;
private uploadEngineVersion(version: string) {
if (this.hasUploadEngineVersion) {
return;
}
if (version) {
this.hasUploadEngineVersion = true;
this.sendEngineVersion(version);
}
}
updateTreeInfo() {
let isCocosCreatorGame = this._isCocosGame();
if (isCocosCreatorGame) {
//@ts-ignore
let scene = cc.director.getScene();
if (scene) {
let treeData = new TreeData();
@@ -617,8 +648,8 @@ export class Inspector extends InjectEvent {
const data: NodeInfoData = new NodeInfoData(uuid, groupData);
this.sendMsgToContent(Msg.ResponseNodeInfo, data as ResponseNodeInfoData);
} else {
// 未获取到节点数据
console.log("未获取到节点数据");
const data: NodeInfoData = new NodeInfoData(uuid, []);
this.sendMsgToContent(Msg.ResponseNodeInfo, data as ResponseNodeInfoData);
}
}