Skip to content

Commit a987862

Browse files
authored
Implement screenshot capture for Unity 2022.1+
Add conditional screenshot capture for Unity 2022.1 and newer.
1 parent 2f2b56a commit a987862

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ public static ScreenshotCaptureResult CaptureToAssetsFolder(string fileName = nu
4141

4242
// Use only the file name to let Unity decide the final location (per CaptureScreenshot docs).
4343
string captureName = Path.GetFileName(normalizedFullPath);
44+
45+
4446
#if UNITY_2022_1_OR_NEWER
4547
ScreenCapture.CaptureScreenshot(captureName, size);
48+
#else
49+
Debug.LogWarning("ScreenCapture is supported after Unity 2022.1. Using main camera capture as fallback.");
50+
CaptureFromCameraToAssetsFolder(Camera.main, captureName, size, false);
4651
#endif
4752

48-
Debug.Log($"Screenshot requested: file='{captureName}' intendedFullPath='{normalizedFullPath}' persistentDataPath='{Application.persistentDataPath}'");
49-
5053
string projectRoot = GetProjectRootPath();
5154
string assetsRelativePath = normalizedFullPath;
5255
if (assetsRelativePath.StartsWith(projectRoot, StringComparison.OrdinalIgnoreCase))

0 commit comments

Comments
 (0)