Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 7 additions & 2 deletions MCPForUnity/Runtime/Helpers/ScreenshotUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static class ScreenshotUtility
private static bool s_loggedLegacyScreenCaptureFallback;
private static bool? s_screenCaptureModuleAvailable;
private static System.Reflection.MethodInfo s_captureScreenshotMethod;
private static System.Reflection.MethodInfo s_captureScreenshotAsTextureMethod;

/// <summary>
/// Checks if the Screen Capture module (com.unity.modules.screencapture) is enabled.
Expand All @@ -72,6 +73,8 @@ public static bool IsScreenCaptureModuleAvailable
{
s_captureScreenshotMethod = screenCaptureType.GetMethod("CaptureScreenshot",
new Type[] { typeof(string), typeof(int) });
s_captureScreenshotAsTextureMethod = screenCaptureType.GetMethod("CaptureScreenshotAsTexture",
new Type[] { typeof(int) });
}
}
return s_screenCaptureModuleAvailable.Value;
Expand Down Expand Up @@ -249,7 +252,7 @@ public static ScreenshotCaptureResult CaptureComposited(
int maxResolution = 0,
string folderOverride = null)
{
if (!IsScreenCaptureModuleAvailable)
if (!IsScreenCaptureModuleAvailable || s_captureScreenshotAsTextureMethod == null)
{
var fallbackCamera = FindAvailableCamera();
if (fallbackCamera != null)
Expand All @@ -266,7 +269,9 @@ public static ScreenshotCaptureResult CaptureComposited(
int imgW = 0, imgH = 0;
try
{
tex = ScreenCapture.CaptureScreenshotAsTexture(result.SuperSize);
// Reflective call to ScreenCapture.CaptureScreenshotAsTexture so the file compiles
// even when the Screen Capture module (com.unity.modules.screencapture) is disabled.
tex = s_captureScreenshotAsTextureMethod.Invoke(null, new object[] { result.SuperSize }) as Texture2D;
if (tex == null)
{
// Fallback to camera-based if ScreenCapture fails
Expand Down
17 changes: 13 additions & 4 deletions MCPForUnity/Runtime/Helpers/UnityPhysicsCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ namespace MCPForUnity.Runtime.Helpers
///
/// We use reflection rather than direct property access so calls stay clean of
/// CS0618 warnings AND survive eventual removal of the obsolete property without
/// a recompile of this package.
/// a recompile of this package. Type lookups go through <see cref="Type.GetType(string)"/>
/// so this file compiles even when the Physics 2D built-in module is disabled in
/// the Package Manager.
/// </summary>
public static class UnityPhysicsCompat
{
// Assembly-qualified name — resolved at runtime so the file compiles when the
// Physics 2D built-in module is disabled in the Package Manager.
private const string Physics2DTypeName = "UnityEngine.Physics2D, UnityEngine.Physics2DModule";
/// <summary>
/// Cross-version description of the 3D physics simulation mode.
/// On 2022.2+ this maps onto <c>UnityEngine.SimulationMode</c>; on older
Expand All @@ -46,9 +51,13 @@ private static PropertyInfo Physics2DAutoSyncProp
if (!_physics2DProbed)
{
_physics2DProbed = true;
_physics2DAutoSync = typeof(Physics2D).GetProperty(
"autoSyncTransforms",
BindingFlags.Public | BindingFlags.Static);
var physics2DType = Type.GetType(Physics2DTypeName);
if (physics2DType != null)
{
_physics2DAutoSync = physics2DType.GetProperty(
"autoSyncTransforms",
BindingFlags.Public | BindingFlags.Static);
}
}
return _physics2DAutoSync;
}
Expand Down
Loading