-
Notifications
You must be signed in to change notification settings - Fork 0
Add manage_editor action for script compilation #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| using MCPForUnity.Editor.Helpers; | ||
| using Newtonsoft.Json.Linq; | ||
| using UnityEditor; | ||
| using UnityEditor.Compilation; | ||
| using UnityEditorInternal; // Required for tag management | ||
|
|
||
| namespace MCPForUnity.Editor.Tools | ||
|
|
@@ -83,6 +84,29 @@ public static object HandleCommand(JObject @params) | |
| { | ||
| return new ErrorResponse($"Error stopping play mode: {e.Message}"); | ||
| } | ||
| case "request_script_compilation": | ||
| try | ||
| { | ||
| bool wasCompiling = CompilationPipeline.isCompiling; | ||
| CompilationPipeline.RequestScriptCompilation(); | ||
| bool nowCompiling = CompilationPipeline.isCompiling; | ||
| string detail = nowCompiling | ||
| ? "Unity reports compilation in progress." | ||
| : "Unity is not currently compiling; if no pending script changes exist, the request may be a no-op."; | ||
| return new SuccessResponse( | ||
| "Script compilation request sent.", | ||
| new | ||
| { | ||
| wasCompiling, | ||
| nowCompiling, | ||
| note = detail | ||
| } | ||
| ); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| return new ErrorResponse($"Error requesting script compilation: {e.Message}"); | ||
| } | ||
|
Comment on lines
+87
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RequestScriptCompilation timing may not reflect actual compilation state. The For more reliable state tracking, consider using the 🤖 Prompt for AI Agents |
||
|
|
||
| // Tool Control | ||
| case "set_active_tool": | ||
|
|
@@ -121,7 +145,7 @@ public static object HandleCommand(JObject @params) | |
|
|
||
| default: | ||
| return new ErrorResponse( | ||
| $"Unknown action: '{action}'. Supported actions: play, pause, stop, set_active_tool, add_tag, remove_tag, add_layer, remove_layer. Use MCP resources for reading editor state, project info, tags, layers, selection, windows, prefab stage, and active tool." | ||
| $"Unknown action: '{action}'. Supported actions: play, pause, stop, request_script_compilation, set_active_tool, add_tag, remove_tag, add_layer, remove_layer. Use MCP resources for reading editor state, project info, tags, layers, selection, windows, prefab stage, and active tool." | ||
| ); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Checking
CompilationPipeline.isCompilingimmediately afterRequestScriptCompilation()may not accurately reflect the compilation state due to async nature. Consider delaying the check or using EditorApplication.update callback.Prompt To Fix With AI