{"repo_name": "unity-mcp", "file_name": "/unity-mcp/UnityMcpBridge/Editor/Tools/ManageEditor.cs", "inference_info": {"prefix_code": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing Newtonsoft.Json.Linq;\nusing UnityEditor;\nusing UnityEditorInternal; // Required for tag management\nusing UnityEngine;\nusing UnityMcpBridge.Editor.Helpers; // For Response class\n\nnamespace UnityMcpBridge.Editor.Tools\n{\n /// \n /// Handles operations related to controlling and querying the Unity Editor state,\n /// including managing Tags and Layers.\n /// \n public static class ManageEditor\n {\n // Constant for starting user layer index\n private const int FirstUserLayerIndex = 8;\n\n // Constant for total layer count\n private const int TotalLayerCount = 32;\n\n /// \n /// Main handler for editor management actions.\n /// \n public static object HandleCommand(JObject @params)\n {\n string action = @params[\"action\"]?.ToString().ToLower();\n // Parameters for specific actions\n string tagName = @params[\"tagName\"]?.ToString();\n string layerName = @params[\"layerName\"]?.ToString();\n bool waitForCompletion = @params[\"waitForCompletion\"]?.ToObject() ?? false; // Example - not used everywhere\n\n if (string.IsNullOrEmpty(action))\n {\n return Response.Error(\"Action parameter is required.\");\n }\n\n // Route action\n switch (action)\n {\n // Play Mode Control\n case \"play\":\n try\n {\n if (!EditorApplication.isPlaying)\n {\n EditorApplication.isPlaying = true;\n return Response.Success(\"Entered play mode.\");\n }\n return Response.Success(\"Already in play mode.\");\n }\n catch (Exception e)\n {\n return Response.Error($\"Error entering play mode: {e.Message}\");\n }\n case \"pause\":\n try\n {\n if (EditorApplication.isPlaying)\n {\n EditorApplication.isPaused = !EditorApplication.isPaused;\n return Response.Success(\n EditorApplication.isPaused ? \"Game paused.\" : \"Game resumed.\"\n );\n }\n return Response.Error(\"Cannot pause/resume: Not in play mode.\");\n }\n catch (Exception e)\n {\n return Response.Error($\"Error pausing/resuming game: {e.Message}\");\n }\n case \"stop\":\n try\n {\n if (EditorApplication.isPlaying)\n {\n EditorApplication.isPlaying = false;\n return Response.Success(\"Exited play mode.\");\n }\n return Response.Success(\"Already stopped (not in play mode).\");\n }\n catch (Exception e)\n {\n return Response.Error($\"Error stopping play mode: {e.Message}\");\n }\n\n // Editor State/Info\n case \"get_state\":\n return GetEditorState();\n case \"get_windows\":\n return GetEditorWindows();\n case \"get_active_tool\":\n return GetActiveTool();\n case \"get_selection\":\n return GetSelection();\n case \"set_active_tool\":\n string toolName = @params[\"toolName\"]?.ToString();\n if (string.IsNullOrEmpty(toolName))\n return Response.Error(\"'toolName' parameter required for set_active_tool.\");\n return SetActiveTool(toolName);\n\n // Tag Management\n case \"add_tag\":\n if (string.IsNullOrEmpty(tagName))\n return Response.Error(\"'tagName' parameter required for add_tag.\");\n return AddTag(tagName);\n case \"remove_tag\":\n if (string.IsNullOrEmpty(tagName))\n return Response.Error(\"'tagName' parameter required for remove_tag.\");\n return RemoveTag(tagName);\n case \"get_tags\":\n return GetTags(); // Helper to list current tags\n\n // Layer Management\n case \"add_layer\":\n if (string.IsNullOrEmpty(layerName))\n return Response.Error(\"'layerName' parameter required for add_layer.\");\n return AddLayer(layerName);\n case \"remove_layer\":\n if (string.IsNullOrEmpty(layerName))\n return Response.Error(\"'layerName' parameter required for remove_layer.\");\n return RemoveLayer(layerName);\n case \"get_layers\":\n return GetLayers(); // Helper to list current layers\n\n // --- Settings (Example) ---\n // case \"set_resolution\":\n // int? width = @params[\"width\"]?.ToObject();\n // int? height = @params[\"height\"]?.ToObject();\n // if (!width.HasValue || !height.HasValue) return Response.Error(\"'width' and 'height' parameters required.\");\n // return SetGameViewResolution(width.Value, height.Value);\n // case \"set_quality\":\n // // Handle string name or int index\n // return SetQualityLevel(@params[\"qualityLevel\"]);\n\n default:\n return Response.Error(\n $\"Unknown action: '{action}'. Supported actions include play, pause, stop, get_state, get_windows, get_active_tool, get_selection, set_active_tool, add_tag, remove_tag, get_tags, add_layer, remove_layer, get_layers.\"\n );\n }\n }\n\n // --- Editor State/Info Methods ---\n private static object GetEditorState()\n {\n try\n {\n var state = new\n {\n isPlaying = EditorApplication.isPlaying,\n isPaused = EditorApplication.isPaused,\n isCompiling = EditorApplication.isCompiling,\n isUpdating = EditorApplication.isUpdating,\n applicationPath = EditorApplication.applicationPath,\n applicationContentsPath = EditorApplication.applicationContentsPath,\n timeSinceStartup = EditorApplication.timeSinceStartup,\n };\n return Response.Success(\"Retrieved editor state.\", state);\n }\n catch (Exception e)\n {\n return Response.Error($\"Error getting editor state: {e.Message}\");\n }\n }\n\n private static object GetEditorWindows()\n {\n try\n {\n // Get all types deriving from EditorWindow\n var windowTypes = AppDomain\n .CurrentDomain.GetAssemblies()\n .SelectMany(assembly => assembly.GetTypes())\n .Where(type => type.IsSubclassOf(typeof(EditorWindow)))\n .ToList();\n\n var openWindows = new List