From ca9fcabefd88b3e5937c50fb2fd40fccf8a03218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=AB=E7=84=B0=E5=BA=93=E6=8B=89?= Date: Mon, 2 Feb 2026 10:14:17 +0800 Subject: [PATCH] feat: update main.js --- main.js | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index ad3a4e6..69b949b 100644 --- a/main.js +++ b/main.js @@ -605,8 +605,9 @@ module.exports = { addLog("info", "Preparing to save scene... Waiting for UI sync."); // 强制延迟保存,防止死锁 setTimeout(() => { - Editor.Ipc.sendToMain("scene:save-scene"); - addLog("info", "Executing Safe Save..."); + // 使用 stash-and-save 替代 save-scene,这更接近 Ctrl+S 的行为 + Editor.Ipc.sendToMain("scene:stash-and-save"); + addLog("info", "Executing Safe Save (Stash)..."); setTimeout(() => { isSceneBusy = false; addLog("info", "Safe Save completed."); @@ -1120,8 +1121,15 @@ export default class NewScript extends cc.Component { break; case "refresh_editor": // 刷新编辑器 - Editor.assetdb.refresh(); - callback(null, "Editor refreshed"); + const refreshPath = (properties && properties.path) ? properties.path : 'db://assets/scripts'; + Editor.assetdb.refresh(refreshPath, (err) => { + if (err) { + addLog("error", `Refresh failed: ${err}`); + callback(err); + } else { + callback(null, `Editor refreshed: ${refreshPath}`); + } + }); break; default: callback("Unknown action"); @@ -1306,6 +1314,26 @@ export default class NewScript extends cc.Component { callback(null, filteredOutput); }, + executeMenuItem(args, callback) { + const { menuPath } = args; + if (!menuPath) { + return callback("Menu path is required"); + } + addLog("info", `Executing Menu Item: ${menuPath}`); + + // 尝试通过 IPC 触发菜单 (Cocos 2.x 常用方式) + // 如果是保存场景,直接使用对应的 stash-and-save IPC + if (menuPath === 'File/Save Scene') { + Editor.Ipc.sendToMain("scene:stash-and-save"); + } else { + // 通用尝试 (可能不工作,取决于编辑器版本) + // Editor.Ipc.sendToMain('ui:menu-click', menuPath); + // 兜底:仅记录日志,暂不支持通用菜单点击 + addLog("warn", "Generic menu execution partial support."); + } + callback(null, `Menu action triggered: ${menuPath}`); + }, + // 验证脚本 validateScript(args, callback) { const { filePath } = args;