Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b80b9ab
Update .Bat file and Bug fix on ManageScript
Scriptwonder Oct 25, 2025
4e9604f
Further changes
Scriptwonder Oct 25, 2025
e63096f
Merge branch 'CoplayDev:main' into main
Scriptwonder Oct 28, 2025
9827775
Merge branch 'CoplayDev:main' into main
Scriptwonder Nov 10, 2025
c5b2d35
[Custom Tool] Roslyn Runtime Compilation
Scriptwonder Nov 10, 2025
8805933
Fix based on CR
Scriptwonder Nov 10, 2025
711e8bd
Create claude_skill_unity.zip
Scriptwonder Nov 13, 2025
f37f534
Merge branch 'CoplayDev:main' into main
Scriptwonder Nov 13, 2025
8caa027
Merge branch 'CoplayDev:main' into main
Scriptwonder Nov 30, 2025
8ebb688
Merge branch 'CoplayDev:main' into main
Scriptwonder Dec 2, 2025
ae8cfe5
Update for Custom_Tool Fix and Detection
Scriptwonder Dec 2, 2025
f423c2f
Revert "Update for Custom_Tool Fix and Detection"
Scriptwonder Dec 2, 2025
b5265a7
Update README.md
Scriptwonder Dec 2, 2025
81b0f50
Reapply "Update for Custom_Tool Fix and Detection"
Scriptwonder Dec 2, 2025
9d967f5
Merge on previous PR
Scriptwonder Dec 2, 2025
5bcb6f4
Update ManageScript.cs
Scriptwonder Dec 2, 2025
ae2eedd
Update
Scriptwonder Dec 3, 2025
318c824
Update on Batch
Scriptwonder Dec 3, 2025
51fc4b4
Merge branch 'main' into batching
Scriptwonder Dec 3, 2025
55ee768
Merge pull request #1 from Scriptwonder/batching
Scriptwonder Dec 3, 2025
2127444
Revert "Merge pull request #1 from Scriptwonder/batching"
Scriptwonder Dec 3, 2025
3f03337
Merge branch 'CoplayDev:main' into main
Scriptwonder Dec 4, 2025
3b30960
Merge branch 'main' into main
Scriptwonder Dec 8, 2025
7b33aaa
Merge remote-tracking branch 'upstream/main'
Scriptwonder Dec 9, 2025
ff7972f
Updates on Camera Capture Feature
Scriptwonder Dec 9, 2025
d7e34b9
Minor changes
Scriptwonder Dec 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 68 additions & 2 deletions MCPForUnity/Editor/Tools/ManageScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using MCPForUnity.Editor.Helpers; // For Response class
using MCPForUnity.Runtime.Helpers; // For ScreenshotUtility
using Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEditor.SceneManagement;
Expand All @@ -23,6 +24,8 @@ private sealed class SceneCommand
public string name { get; set; } = string.Empty;
public string path { get; set; } = string.Empty;
public int? buildIndex { get; set; }
public string fileName { get; set; } = string.Empty;
public int? superSize { get; set; }
}

private static SceneCommand ToSceneCommand(JObject p)
Expand All @@ -42,7 +45,9 @@ private static SceneCommand ToSceneCommand(JObject p)
action = (p["action"]?.ToString() ?? string.Empty).Trim().ToLowerInvariant(),
name = p["name"]?.ToString() ?? string.Empty,
path = p["path"]?.ToString() ?? string.Empty,
buildIndex = BI(p["buildIndex"] ?? p["build_index"])
buildIndex = BI(p["buildIndex"] ?? p["build_index"]),
fileName = (p["fileName"] ?? p["filename"])?.ToString() ?? string.Empty,
superSize = BI(p["superSize"] ?? p["super_size"] ?? p["supersize"])
};
}

Expand Down Expand Up @@ -142,14 +147,26 @@ public static object HandleCommand(JObject @params)
return ga;
case "get_build_settings":
return GetBuildSettingsScenes();
case "screenshot":
return CaptureScreenshot(cmd.fileName, cmd.superSize);
// Add cases for modifying build settings, additive loading, unloading etc.
default:
return new ErrorResponse(
$"Unknown action: '{action}'. Valid actions: create, load, save, get_hierarchy, get_active, get_build_settings."
$"Unknown action: '{action}'. Valid actions: create, load, save, get_hierarchy, get_active, get_build_settings, screenshot."
);
}
}

/// <summary>
/// Captures a screenshot to Assets/Screenshots and returns a response payload.
/// Public so the tools UI can reuse the same logic without duplicating parameters.
/// Available in both Edit Mode and Play Mode.
/// </summary>
public static object ExecuteScreenshot(string fileName = null, int? superSize = null)
{
return CaptureScreenshot(fileName, superSize);
}

private static object CreateScene(string fullPath, string relativePath)
{
if (File.Exists(fullPath))
Expand Down Expand Up @@ -329,6 +346,55 @@ private static object SaveScene(string fullPath, string relativePath)
}
}

private static object CaptureScreenshot(string fileName, int? superSize)
{
try
{
int resolvedSuperSize = (superSize.HasValue && superSize.Value > 0) ? superSize.Value : 1;
ScreenshotCaptureResult result;

if (Application.isPlaying)
{
result = ScreenshotUtility.CaptureToAssetsFolder(fileName, resolvedSuperSize, ensureUniqueFileName: true);
}
else
{
// Edit Mode path: render from the best-guess camera using RenderTexture.
Camera cam = Camera.main;
if (cam == null)
{
var cams = UnityEngine.Object.FindObjectsOfType<Camera>();
cam = cams.FirstOrDefault();
}

if (cam == null)
{
return new ErrorResponse("No camera found to capture screenshot in Edit Mode.");
}

result = ScreenshotUtility.CaptureFromCameraToAssetsFolder(cam, fileName, resolvedSuperSize, ensureUniqueFileName: true);
}

AssetDatabase.Refresh();

string message = $"Screenshot captured to '{result.AssetsRelativePath}' (full: {result.FullPath}).";

return new SuccessResponse(
message,
new
{
path = result.AssetsRelativePath,
fullPath = result.FullPath,
superSize = result.SuperSize,
}
);
}
catch (Exception e)
{
return new ErrorResponse($"Error capturing screenshot: {e.Message}");
}
}

private static object GetActiveSceneInfo()
{
try
Expand Down
49 changes: 49 additions & 0 deletions MCPForUnity/Editor/Windows/Components/Tools/McpToolsSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using MCPForUnity.Editor.Constants;
using MCPForUnity.Editor.Helpers;
using MCPForUnity.Editor.Services;
using MCPForUnity.Editor.Tools;
using UnityEditor;
using UnityEngine.UIElements;

Expand Down Expand Up @@ -199,6 +200,11 @@ private VisualElement CreateToolRow(ToolMetadata tool)
row.Add(parametersLabel);
}

if (IsManageSceneTool(tool))
{
row.Add(CreateManageSceneActions());
}

return row;
}

Expand Down Expand Up @@ -258,13 +264,56 @@ private void AddInfoLabel(string message)
categoryContainer?.Add(label);
}

private VisualElement CreateManageSceneActions()
{
var actions = new VisualElement();
actions.AddToClassList("tool-item-actions");

var screenshotButton = new Button(OnManageSceneScreenshotClicked)
{
text = "Capture Screenshot"
};
screenshotButton.AddToClassList("tool-action-button");
screenshotButton.style.marginTop = 4;
screenshotButton.tooltip = "Capture a screenshot to Assets/Screenshots via manage_scene.";

actions.Add(screenshotButton);
return actions;
}

private void OnManageSceneScreenshotClicked()
{
try
{
var response = ManageScene.ExecuteScreenshot();
if (response is SuccessResponse success && !string.IsNullOrWhiteSpace(success.Message))
{
McpLog.Info(success.Message);
}
else if (response is ErrorResponse error && !string.IsNullOrWhiteSpace(error.Error))
{
McpLog.Error(error.Error);
}
else
{
McpLog.Info("Screenshot capture requested.");
}
}
catch (Exception ex)
{
McpLog.Error($"Failed to capture screenshot: {ex.Message}");
}
}

private static Label CreateTag(string text)
{
var tag = new Label(text);
tag.AddToClassList("tool-tag");
return tag;
}

private static bool IsManageSceneTool(ToolMetadata tool) => string.Equals(tool?.Name, "manage_scene", StringComparison.OrdinalIgnoreCase);

private static bool IsBuiltIn(ToolMetadata tool) => tool?.IsBuiltIn ?? false;
}
}
Loading