From a9878622eae5e1a57d77361fcab37eb19183c08b Mon Sep 17 00:00:00 2001 From: Shutong Wu <51266340+Scriptwonder@users.noreply.github.com> Date: Wed, 10 Dec 2025 12:15:29 -0500 Subject: [PATCH] Implement screenshot capture for Unity 2022.1+ Add conditional screenshot capture for Unity 2022.1 and newer. --- MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs b/MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs index 1408f21..4fc967f 100644 --- a/MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs +++ b/MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs @@ -41,12 +41,15 @@ namespace MCPForUnity.Runtime.Helpers // Use only the file name to let Unity decide the final location (per CaptureScreenshot docs). string captureName = Path.GetFileName(normalizedFullPath); + + #if UNITY_2022_1_OR_NEWER ScreenCapture.CaptureScreenshot(captureName, size); +#else + Debug.LogWarning("ScreenCapture is supported after Unity 2022.1. Using main camera capture as fallback."); + CaptureFromCameraToAssetsFolder(Camera.main, captureName, size, false); #endif - Debug.Log($"Screenshot requested: file='{captureName}' intendedFullPath='{normalizedFullPath}' persistentDataPath='{Application.persistentDataPath}'"); - string projectRoot = GetProjectRootPath(); string assetsRelativePath = normalizedFullPath; if (assetsRelativePath.StartsWith(projectRoot, StringComparison.OrdinalIgnoreCase))