77using Newtonsoft . Json . Linq ;
88using UnityEditor ;
99using UnityEngine ;
10+ using MCPForUnity . Runtime . Helpers ;
1011
1112namespace MCPForUnity . Editor . Helpers
1213{
@@ -28,7 +29,7 @@ public static object GetGameObjectData(GameObject go)
2829 return new
2930 {
3031 name = go . name ,
31- instanceID = go . GetInstanceID ( ) ,
32+ instanceID = go . GetInstanceIDCompat ( ) ,
3233 tag = go . tag ,
3334 layer = go . layer ,
3435 activeSelf = go . activeSelf ,
@@ -88,7 +89,7 @@ public static object GetGameObjectData(GameObject go)
8889 z = go . transform . right . z ,
8990 } ,
9091 } ,
91- parentInstanceID = go . transform . parent ? . gameObject . GetInstanceID ( ) ?? 0 , // 0 if no parent
92+ parentInstanceID = go . transform . parent ? . gameObject . GetInstanceIDCompat ( ) ?? 0 , // 0 if no parent
9293 // Optionally include components, but can be large
9394 // components = go.GetComponents<Component>().Select(c => GetComponentData(c)).ToList()
9495 // Or just component names:
@@ -144,7 +145,7 @@ private static Dictionary<string, object> SerializeAssetReference(UnityEngine.Ob
144145 var result = new Dictionary < string , object >
145146 {
146147 { "name" , obj . name } ,
147- { "instanceID" , obj . GetInstanceID ( ) }
148+ { "instanceID" , obj . GetInstanceIDCompat ( ) }
148149 } ;
149150
150151 if ( includeAssetPath )
@@ -164,7 +165,7 @@ private static Dictionary<string, object> SerializeAssetReference(UnityEngine.Ob
164165 public static object GetComponentData ( Component c , bool includeNonPublicSerializedFields = true )
165166 {
166167 // --- Add Early Logging ---
167- // McpLog.Info($"[GetComponentData] Starting for component: {c?.GetType()?.FullName ?? "null"} (ID: {c?.GetInstanceID () ?? 0})");
168+ // McpLog.Info($"[GetComponentData] Starting for component: {c?.GetType()?.FullName ?? "null"} (ID: {c?.GetInstanceIDCompat () ?? 0})");
168169 // --- End Early Logging ---
169170
170171 if ( c == null ) return null ;
@@ -174,11 +175,11 @@ public static object GetComponentData(Component c, bool includeNonPublicSerializ
174175 if ( componentType == typeof ( Transform ) )
175176 {
176177 Transform tr = c as Transform ;
177- // McpLog.Info($"[GetComponentData] Manually serializing Transform (ID: {tr.GetInstanceID ()})");
178+ // McpLog.Info($"[GetComponentData] Manually serializing Transform (ID: {tr.GetInstanceIDCompat ()})");
178179 return new Dictionary < string , object >
179180 {
180181 { "typeName" , componentType . FullName } ,
181- { "instanceID" , tr . GetInstanceID ( ) } ,
182+ { "instanceID" , tr . GetInstanceIDCompat ( ) } ,
182183 // Manually extract known-safe properties. Avoid Quaternion 'rotation' and 'lossyScale'.
183184 { "position" , CreateTokenFromValue ( tr . position , typeof ( Vector3 ) ) ? . ToObject < object > ( ) ?? new JObject ( ) } ,
184185 { "localPosition" , CreateTokenFromValue ( tr . localPosition , typeof ( Vector3 ) ) ? . ToObject < object > ( ) ?? new JObject ( ) } ,
@@ -188,13 +189,13 @@ public static object GetComponentData(Component c, bool includeNonPublicSerializ
188189 { "right" , CreateTokenFromValue ( tr . right , typeof ( Vector3 ) ) ? . ToObject < object > ( ) ?? new JObject ( ) } ,
189190 { "up" , CreateTokenFromValue ( tr . up , typeof ( Vector3 ) ) ? . ToObject < object > ( ) ?? new JObject ( ) } ,
190191 { "forward" , CreateTokenFromValue ( tr . forward , typeof ( Vector3 ) ) ? . ToObject < object > ( ) ?? new JObject ( ) } ,
191- { "parentInstanceID" , tr . parent ? . gameObject . GetInstanceID ( ) ?? 0 } ,
192- { "rootInstanceID" , tr . root ? . gameObject . GetInstanceID ( ) ?? 0 } ,
192+ { "parentInstanceID" , tr . parent ? . gameObject . GetInstanceIDCompat ( ) ?? 0 } ,
193+ { "rootInstanceID" , tr . root ? . gameObject . GetInstanceIDCompat ( ) ?? 0 } ,
193194 { "childCount" , tr . childCount } ,
194195 // Include standard Object/Component properties
195196 { "name" , tr . name } ,
196197 { "tag" , tr . tag } ,
197- { "gameObjectInstanceID" , tr . gameObject ? . GetInstanceID ( ) ?? 0 }
198+ { "gameObjectInstanceID" , tr . gameObject ? . GetInstanceIDCompat ( ) ?? 0 }
198199 } ;
199200 }
200201 // --- End Special handling for Transform ---
@@ -233,7 +234,7 @@ public static object GetComponentData(Component c, bool includeNonPublicSerializ
233234 { "enabled" , ( ) => cam . enabled } ,
234235 { "name" , ( ) => cam . name } ,
235236 { "tag" , ( ) => cam . tag } ,
236- { "gameObject" , ( ) => new { name = cam . gameObject . name , instanceID = cam . gameObject . GetInstanceID ( ) } }
237+ { "gameObject" , ( ) => new { name = cam . gameObject . name , instanceID = cam . gameObject . GetInstanceIDCompat ( ) } }
237238 } ;
238239
239240 foreach ( var prop in safeProperties )
@@ -256,7 +257,7 @@ public static object GetComponentData(Component c, bool includeNonPublicSerializ
256257 return new Dictionary < string , object >
257258 {
258259 { "typeName" , componentType . FullName } ,
259- { "instanceID" , cam . GetInstanceID ( ) } ,
260+ { "instanceID" , cam . GetInstanceIDCompat ( ) } ,
260261 { "properties" , cameraProperties }
261262 } ;
262263 }
@@ -322,7 +323,7 @@ public static object GetComponentData(Component c, bool includeNonPublicSerializ
322323 return new Dictionary < string , object >
323324 {
324325 { "typeName" , componentType . FullName } ,
325- { "instanceID" , c . GetInstanceID ( ) } ,
326+ { "instanceID" , c . GetInstanceIDCompat ( ) } ,
326327 { "properties" , uiDocProperties }
327328 } ;
328329 }
@@ -331,7 +332,7 @@ public static object GetComponentData(Component c, bool includeNonPublicSerializ
331332 var data = new Dictionary < string , object >
332333 {
333334 { "typeName" , componentType . FullName } ,
334- { "instanceID" , c . GetInstanceID ( ) }
335+ { "instanceID" , c . GetInstanceIDCompat ( ) }
335336 } ;
336337
337338 // --- Get Cached or Generate Metadata (using new cache key) ---
0 commit comments