@@ -11,7 +11,9 @@ namespace MCPForUnity.Editor.Tools.Profiler
1111 internal static class MemorySnapshotOps
1212 {
1313 private static readonly Type MemoryProfilerType =
14- Type . GetType ( "Unity.MemoryProfiler.MemoryProfiler, Unity.MemoryProfiler.Editor" ) ;
14+ Type . GetType ( "Unity.Profiling.Memory.MemoryProfiler, UnityEngine.CoreModule" )
15+ ?? Type . GetType ( "UnityEngine.Profiling.Memory.Experimental.MemoryProfiler, UnityEngine.CoreModule" )
16+ ?? Type . GetType ( "Unity.MemoryProfiler.MemoryProfiler, Unity.MemoryProfiler.Editor" ) ;
1517
1618 private static bool HasPackage => MemoryProfilerType != null ;
1719
@@ -35,11 +37,30 @@ internal static async Task<object> TakeSnapshotAsync(JObject @params)
3537 try
3638 {
3739 var debugScreenCaptureType = Type . GetType (
38- "Unity.Profiling.Memory.Experimental.DebugScreenCapture, Unity.MemoryProfiler.Editor" ) ;
40+ "Unity.Profiling.DebugScreenCapture, UnityEngine.CoreModule" )
41+ ?? Type . GetType ( "UnityEngine.Profiling.Experimental.DebugScreenCapture, UnityEngine.CoreModule" )
42+ ?? Type . GetType ( "Unity.Profiling.Memory.Experimental.DebugScreenCapture, Unity.MemoryProfiler.Editor" ) ;
43+ var captureFlagsType = Type . GetType (
44+ "Unity.Profiling.Memory.CaptureFlags, UnityEngine.CoreModule" )
45+ ?? Type . GetType ( "UnityEngine.Profiling.Memory.Experimental.CaptureFlags, UnityEngine.CoreModule" ) ;
3946
4047 System . Reflection . MethodInfo takeMethod = null ;
4148
42- if ( debugScreenCaptureType != null )
49+ if ( debugScreenCaptureType != null && captureFlagsType != null )
50+ {
51+ var screenshotCallbackType = typeof ( Action < , , > ) . MakeGenericType (
52+ typeof ( string ) , typeof ( bool ) , debugScreenCaptureType ) ;
53+ takeMethod = MemoryProfilerType . GetMethod ( "TakeSnapshot" ,
54+ new [ ] { typeof ( string ) , typeof ( Action < string , bool > ) , screenshotCallbackType , captureFlagsType } ) ;
55+ }
56+
57+ if ( takeMethod == null && captureFlagsType != null )
58+ {
59+ takeMethod = MemoryProfilerType . GetMethod ( "TakeSnapshot" ,
60+ new [ ] { typeof ( string ) , typeof ( Action < string , bool > ) , captureFlagsType } ) ;
61+ }
62+
63+ if ( takeMethod == null && debugScreenCaptureType != null )
4364 {
4465 var screenshotCallbackType = typeof ( Action < , , > ) . MakeGenericType (
4566 typeof ( string ) , typeof ( bool ) , debugScreenCaptureType ) ;
@@ -49,7 +70,6 @@ internal static async Task<object> TakeSnapshotAsync(JObject @params)
4970
5071 if ( takeMethod == null )
5172 {
52- // Try 2-param overload: TakeSnapshot(string, Action<string, bool>)
5373 takeMethod = MemoryProfilerType . GetMethod ( "TakeSnapshot" ,
5474 new [ ] { typeof ( string ) , typeof ( Action < string , bool > ) } ) ;
5575 }
@@ -75,8 +95,13 @@ internal static async Task<object> TakeSnapshotAsync(JObject @params)
7595 }
7696 } ;
7797
78- int paramCount = takeMethod . GetParameters ( ) . Length ;
79- if ( paramCount == 4 )
98+ var takeMethodParams = takeMethod . GetParameters ( ) ;
99+ int paramCount = takeMethodParams . Length ;
100+ if ( paramCount == 4 && takeMethodParams [ 3 ] . ParameterType == captureFlagsType )
101+ takeMethod . Invoke ( null , new object [ ] { snapshotPath , callback , null , Enum . ToObject ( captureFlagsType , 0 ) } ) ;
102+ else if ( paramCount == 3 && takeMethodParams [ 2 ] . ParameterType == captureFlagsType )
103+ takeMethod . Invoke ( null , new object [ ] { snapshotPath , callback , Enum . ToObject ( captureFlagsType , 0 ) } ) ;
104+ else if ( paramCount == 4 && takeMethodParams [ 3 ] . ParameterType == typeof ( uint ) )
80105 takeMethod . Invoke ( null , new object [ ] { snapshotPath , callback , null , 0u } ) ;
81106 else if ( paramCount == 2 )
82107 takeMethod . Invoke ( null , new object [ ] { snapshotPath , callback } ) ;
@@ -98,9 +123,6 @@ internal static async Task<object> TakeSnapshotAsync(JObject @params)
98123
99124 internal static object ListSnapshots ( JObject @params )
100125 {
101- if ( ! HasPackage )
102- return PackageMissingError ( ) ;
103-
104126 var p = new ToolParams ( @params ) ;
105127 string searchPath = p . Get ( "search_path" ) ;
106128
@@ -141,9 +163,6 @@ internal static object ListSnapshots(JObject @params)
141163
142164 internal static object CompareSnapshots ( JObject @params )
143165 {
144- if ( ! HasPackage )
145- return PackageMissingError ( ) ;
146-
147166 var p = new ToolParams ( @params ) ;
148167 var pathAResult = p . GetRequired ( "snapshot_a" ) ;
149168 if ( ! pathAResult . IsSuccess )
0 commit comments