diff --git a/UnityMcpBridge/Editor/Tools/ManageScript.cs b/UnityMcpBridge/Editor/Tools/ManageScript.cs index 7ec6afe9..73f48677 100644 --- a/UnityMcpBridge/Editor/Tools/ManageScript.cs +++ b/UnityMcpBridge/Editor/Tools/ManageScript.cs @@ -2568,6 +2568,8 @@ public static void Schedule(string relPath, TimeSpan window) // Kick off a ticking callback that waits until the window has elapsed // from the last request before performing the refresh. EditorApplication.delayCall += () => Tick(window); + // Nudge the editor loop so ticks run even if the window is unfocused + EditorApplication.QueuePlayerLoopUpdate(); } private static void Tick(TimeSpan window) @@ -2595,7 +2597,10 @@ private static void Tick(TimeSpan window) string[] toImport; lock (_lock) { toImport = _paths.ToArray(); _paths.Clear(); } foreach (var p in toImport) - AssetDatabase.ImportAsset(p, ImportAssetOptions.ForceUpdate); + { + var sp = ManageScriptRefreshHelpers.SanitizeAssetsPath(p); + AssetDatabase.ImportAsset(sp, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport); + } #if UNITY_EDITOR UnityEditor.Compilation.CompilationPipeline.RequestScriptCompilation(); #endif @@ -2607,16 +2612,31 @@ private static void Tick(TimeSpan window) static class ManageScriptRefreshHelpers { + public static string SanitizeAssetsPath(string p) + { + if (string.IsNullOrEmpty(p)) return p; + p = p.Replace('\\', '/').Trim(); + if (p.StartsWith("unity://path/", StringComparison.OrdinalIgnoreCase)) + p = p.Substring("unity://path/".Length); + while (p.StartsWith("Assets/Assets/", StringComparison.OrdinalIgnoreCase)) + p = p.Substring("Assets/".Length); + if (!p.StartsWith("Assets/", StringComparison.OrdinalIgnoreCase)) + p = "Assets/" + p.TrimStart('/'); + return p; + } + public static void ScheduleScriptRefresh(string relPath) { - RefreshDebounce.Schedule(relPath, TimeSpan.FromMilliseconds(200)); + var sp = SanitizeAssetsPath(relPath); + RefreshDebounce.Schedule(sp, TimeSpan.FromMilliseconds(200)); } public static void ImportAndRequestCompile(string relPath, bool synchronous = true) { + var sp = SanitizeAssetsPath(relPath); var opts = ImportAssetOptions.ForceUpdate; if (synchronous) opts |= ImportAssetOptions.ForceSynchronousImport; - AssetDatabase.ImportAsset(relPath, opts); + AssetDatabase.ImportAsset(sp, opts); #if UNITY_EDITOR UnityEditor.Compilation.CompilationPipeline.RequestScriptCompilation(); #endif diff --git a/UnityMcpBridge/UnityMcpServer~/src/server_version.txt b/UnityMcpBridge/UnityMcpServer~/src/server_version.txt index 94ff29cc..944880fa 100644 --- a/UnityMcpBridge/UnityMcpServer~/src/server_version.txt +++ b/UnityMcpBridge/UnityMcpServer~/src/server_version.txt @@ -1 +1 @@ -3.1.1 +3.2.0