cocos creator 插件开发小知识
编辑器
- 获取预览地址
/** cocos 编辑器窗口对象 */ const cocos_window = ((electron as any).remote as typeof electron).BrowserWindow.getAllWindows().find( (v) => v.title !== "CocosCreator" && v.title.includes("Cocos Creator") )!; /** 预览地址 */ let preview_url_s = await cocos_window.webContents.executeJavaScript("window.xxx.address"); // 不存在预览地址 if (!preview_url_s) { await cocos_window.webContents.executeJavaScript( 'window.xxx.$refs.qr.parentElement.dispatchEvent(new Event("mouseenter")); window.xxx.$refs.qr.parentElement.dispatchEvent(new Event("click"))' ); await new Promise<void>((resolve_f) => { const timer = setInterval(async () => { preview_url_s = await cocos_window.webContents.executeJavaScript("window.xxx.address"); if (preview_url_s) { clearInterval(timer); resolve_f(); } }, 10); }); cocos_window.webContents.executeJavaScript('window.xxx.$refs.qr.parentElement.dispatchEvent(new Event("mouseleave"))'); }
窗口
- 获取当前打开的窗口对象
const window_id_ns = electron.BrowserWindow.getAllWindows().map((v) => v.id);
await Editor.Panel.open(config.name_s);
const window = electron.BrowserWindow.getAllWindows().find((v) => !window_id_ns.includes(v.id))!;
本文来自博客园,作者:Muzzik,转载请注明原文链接:https://www.cnblogs.com/muzzik/p/17322459.html