From 2f2b56a20dbdaefc94ed192c201a39829e4b637b Mon Sep 17 00:00:00 2001 From: Evan Date: Thu, 11 Dec 2025 01:14:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DArrayPool=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E4=BC=9A=E4=BA=A7=E7=94=9F=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#451)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed ArrayPool conflict with CString.dll ArrayPool in Tolua Fixed ArrayPool conflict with CString.dll ArrayPool in Tolua * ScreenCapture在Unity2022中才支持 ScreenCapture在Unity2022中才支持,增加Unity版本判断 --- .../Services/Transport/Transports/WebSocketTransportClient.cs | 4 ++-- MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs b/MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs index ae62aaf..f2beb1f 100644 --- a/MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs +++ b/MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs @@ -345,7 +345,7 @@ namespace MCPForUnity.Editor.Services.Transport.Transports return null; } - byte[] rentedBuffer = ArrayPool.Shared.Rent(8192); + byte[] rentedBuffer = System.Buffers.ArrayPool.Shared.Rent(8192); var buffer = new ArraySegment(rentedBuffer); using var ms = new MemoryStream(8192); @@ -381,7 +381,7 @@ namespace MCPForUnity.Editor.Services.Transport.Transports } finally { - ArrayPool.Shared.Return(rentedBuffer); + System.Buffers.ArrayPool.Shared.Return(rentedBuffer); } } diff --git a/MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs b/MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs index 81cefa3..1408f21 100644 --- a/MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs +++ b/MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs @@ -41,7 +41,9 @@ 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); +#endif Debug.Log($"Screenshot requested: file='{captureName}' intendedFullPath='{normalizedFullPath}' persistentDataPath='{Application.persistentDataPath}'");