Skip to content

Commit 77a64c6

Browse files
committed
Update
1 parent 0f0eacf commit 77a64c6

3 files changed

Lines changed: 42 additions & 5 deletions

File tree

MCPForUnity/Editor/Tools/ManageBuild.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,42 @@ private static object HandleScenes(ToolParams p)
310310
return new SuccessResponse($"Build scenes ({scenes.Length}).", new { scenes });
311311
}
312312

313-
// Write scene list
313+
// Handle string input: try JSON parse, then comma-separated
314+
if (scenesRaw.Type == JTokenType.String)
315+
{
316+
string scenesStr = scenesRaw.ToString();
317+
try { scenesRaw = JArray.Parse(scenesStr); }
318+
catch
319+
{
320+
// Treat as comma-separated paths
321+
var paths = scenesStr.Split(',')
322+
.Select(s => s.Trim())
323+
.Where(s => !string.IsNullOrEmpty(s))
324+
.ToArray();
325+
if (paths.Length == 0)
326+
return new ErrorResponse("'scenes' string contained no valid paths.");
327+
var fromStr = paths.Select(sp => new EditorBuildSettingsScene(sp, true)).ToArray();
328+
EditorBuildSettings.scenes = fromStr;
329+
return new SuccessResponse($"Updated build scenes ({fromStr.Length}).", new
330+
{
331+
scenes = fromStr.Select(s => new { path = s.path, enabled = s.enabled }).ToArray()
332+
});
333+
}
334+
}
335+
336+
// Write scene list — accepts array of strings or array of {path, enabled} objects
314337
var sceneArray = scenesRaw as JArray;
315338
if (sceneArray == null)
316-
return new ErrorResponse("'scenes' must be an array of {path, enabled} objects.");
339+
return new ErrorResponse("'scenes' must be an array of scene paths or {path, enabled} objects.");
317340

318341
var newScenes = new List<EditorBuildSettingsScene>();
319342
foreach (var item in sceneArray)
320343
{
344+
if (item.Type == JTokenType.String)
345+
{
346+
newScenes.Add(new EditorBuildSettingsScene(item.ToString(), true));
347+
continue;
348+
}
321349
string path = item["path"]?.ToString();
322350
if (string.IsNullOrEmpty(path))
323351
return new ErrorResponse("Each scene must have a 'path' field.");
@@ -373,8 +401,9 @@ private static object HandleProfiles(ToolParams p)
373401
});
374402
}
375403

376-
// Get profile details
377-
var profileScenes = loadedProfile.GetScenesForBuild()
404+
// Get profile details — use .scenes (available since Unity 6000.0.0)
405+
// instead of .GetScenesForBuild() which was added in 6000.0.36
406+
var profileScenes = loadedProfile.scenes
378407
.Select(s => s.path).ToArray();
379408
return new SuccessResponse($"Profile: {profilePath}", new
380409
{

MCPForUnity/Editor/Tools/ManageScene.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ public static object HandleCommand(JObject @params)
178178
{
179179
relativeDir = relativeDir.Substring("Assets/".Length).TrimStart('/');
180180
}
181+
// If path ends with .unity, it's a full scene path — extract just the directory
182+
if (relativeDir.EndsWith(".unity", StringComparison.OrdinalIgnoreCase))
183+
{
184+
string dirPart = Path.GetDirectoryName(relativeDir);
185+
relativeDir = string.IsNullOrEmpty(dirPart)
186+
? string.Empty
187+
: AssetPathUtility.NormalizeSeparators(dirPart);
188+
}
181189
}
182190

183191
// Apply default *after* sanitizing, using the original path variable for the check

Server/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)