Skip to content

Commit 294c325

Browse files
authored
Merge pull request #1058 from Scriptwonder/pr-1051-unity65-compat
Pr 1051 unity65 compat
2 parents 6948193 + f69acf0 commit 294c325

37 files changed

Lines changed: 306 additions & 199 deletions

MCPForUnity/Editor/Helpers/ComponentOps.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using UnityEditor;
66
using UnityEngine;
77
using UnityEngine.Events;
8+
using MCPForUnity.Runtime.Helpers;
89

910
namespace MCPForUnity.Editor.Helpers
1011
{
@@ -977,7 +978,7 @@ private static long GetSpriteFileId(Sprite sprite)
977978
}
978979
catch (Exception ex)
979980
{
980-
McpLog.Warn($"Failed to get fileID for sprite '{sprite.name}' (instanceID={sprite.GetInstanceID()}): {ex.Message}");
981+
McpLog.Warn($"Failed to get fileID for sprite '{sprite.name}' (instanceID={sprite.GetInstanceIDCompat()}): {ex.Message}");
981982
return 0;
982983
}
983984
}

MCPForUnity/Editor/Helpers/GameObjectLookup.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using UnityEditor.SceneManagement;
77
using UnityEngine;
88
using UnityEngine.SceneManagement;
9+
using MCPForUnity.Runtime.Helpers;
910

1011
namespace MCPForUnity.Editor.Helpers
1112
{
@@ -155,7 +156,7 @@ private static IEnumerable<int> SearchByName(string name, bool includeInactive,
155156
if (maxResults > 0)
156157
matching = matching.Take(maxResults);
157158

158-
return matching.Select(go => go.GetInstanceID());
159+
return matching.Select(go => go.GetInstanceIDCompat());
159160
}
160161

161162
private static IEnumerable<int> SearchByPath(string path, bool includeInactive)
@@ -170,7 +171,7 @@ private static IEnumerable<int> SearchByPath(string path, bool includeInactive)
170171
{
171172
if (MatchesPath(go, path))
172173
{
173-
yield return go.GetInstanceID();
174+
yield return go.GetInstanceIDCompat();
174175
}
175176
}
176177
yield break;
@@ -187,7 +188,7 @@ private static IEnumerable<int> SearchByPath(string path, bool includeInactive)
187188
{
188189
if (MatchesPath(go, path))
189190
{
190-
yield return go.GetInstanceID();
191+
yield return go.GetInstanceIDCompat();
191192
}
192193
}
193194
}
@@ -197,7 +198,7 @@ private static IEnumerable<int> SearchByPath(string path, bool includeInactive)
197198
var found = GameObject.Find(path);
198199
if (found != null)
199200
{
200-
yield return found.GetInstanceID();
201+
yield return found.GetInstanceIDCompat();
201202
}
202203
}
203204
}
@@ -230,7 +231,7 @@ private static IEnumerable<int> SearchByTag(string tag, bool includeInactive, in
230231

231232
foreach (var go in results)
232233
{
233-
yield return go.GetInstanceID();
234+
yield return go.GetInstanceIDCompat();
234235
}
235236
}
236237

@@ -254,7 +255,7 @@ private static IEnumerable<int> SearchByLayer(string layerName, bool includeInac
254255

255256
foreach (var go in matching)
256257
{
257-
yield return go.GetInstanceID();
258+
yield return go.GetInstanceIDCompat();
258259
}
259260
}
260261

@@ -274,7 +275,7 @@ private static IEnumerable<int> SearchByComponent(string componentTypeName, bool
274275
{
275276
if (go.GetComponent(componentType) != null)
276277
{
277-
yield return go.GetInstanceID();
278+
yield return go.GetInstanceIDCompat();
278279
count++;
279280

280281
if (maxResults > 0 && count >= maxResults)

MCPForUnity/Editor/Helpers/GameObjectSerializer.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Newtonsoft.Json.Linq;
88
using UnityEditor;
99
using UnityEngine;
10+
using MCPForUnity.Runtime.Helpers;
1011

1112
namespace 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) ---

MCPForUnity/Editor/Resources/Editor/Selection.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using MCPForUnity.Editor.Helpers;
44
using Newtonsoft.Json.Linq;
55
using UnityEditor;
6+
using MCPForUnity.Runtime.Helpers;
67

78
namespace MCPForUnity.Editor.Resources.Editor
89
{
@@ -21,21 +22,21 @@ public static object HandleCommand(JObject @params)
2122
activeObject = UnityEditor.Selection.activeObject?.name,
2223
activeGameObject = UnityEditor.Selection.activeGameObject?.name,
2324
activeTransform = UnityEditor.Selection.activeTransform?.name,
24-
activeInstanceID = UnityEditor.Selection.activeObject?.GetInstanceID() ?? 0,
25+
activeInstanceID = UnityEditor.Selection.activeObject?.GetInstanceIDCompat() ?? 0,
2526
count = UnityEditor.Selection.count,
2627
objects = UnityEditor.Selection.objects
2728
.Select(obj => new
2829
{
2930
name = obj?.name,
3031
type = obj?.GetType().FullName,
31-
instanceID = obj?.GetInstanceID()
32+
instanceID = obj?.GetInstanceIDCompat()
3233
})
3334
.ToList(),
3435
gameObjects = UnityEditor.Selection.gameObjects
3536
.Select(go => new
3637
{
3738
name = go?.name,
38-
instanceID = go?.GetInstanceID()
39+
instanceID = go?.GetInstanceIDCompat()
3940
})
4041
.ToList(),
4142
assetGUIDs = UnityEditor.Selection.assetGUIDs

MCPForUnity/Editor/Resources/Editor/Windows.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Newtonsoft.Json.Linq;
55
using UnityEditor;
66
using UnityEngine;
7+
using MCPForUnity.Runtime.Helpers;
78

89
namespace MCPForUnity.Editor.Resources.Editor
910
{
@@ -39,7 +40,7 @@ public static object HandleCommand(JObject @params)
3940
width = window.position.width,
4041
height = window.position.height
4142
},
42-
instanceID = window.GetInstanceID()
43+
instanceID = window.GetInstanceIDCompat()
4344
});
4445
}
4546
catch (Exception ex)

MCPForUnity/Editor/Resources/Scene/GameObjectResource.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Newtonsoft.Json.Linq;
66
using UnityEditor;
77
using UnityEngine;
8+
using MCPForUnity.Runtime.Helpers;
89

910
namespace MCPForUnity.Editor.Resources.Scene
1011
{
@@ -84,12 +85,12 @@ public static object SerializeGameObject(GameObject go)
8485
var childrenIds = new List<int>();
8586
foreach (Transform child in transform)
8687
{
87-
childrenIds.Add(child.gameObject.GetInstanceID());
88+
childrenIds.Add(child.gameObject.GetInstanceIDCompat());
8889
}
8990

9091
return new
9192
{
92-
instanceID = go.GetInstanceID(),
93+
instanceID = go.GetInstanceIDCompat(),
9394
name = go.name,
9495
tag = go.tag,
9596
layer = go.layer,
@@ -106,7 +107,7 @@ public static object SerializeGameObject(GameObject go)
106107
scale = SerializeVector3(transform.localScale),
107108
lossyScale = SerializeVector3(transform.lossyScale)
108109
},
109-
parent = transform.parent != null ? transform.parent.gameObject.GetInstanceID() : (int?)null,
110+
parent = transform.parent != null ? transform.parent.gameObject.GetInstanceIDCompat() : (int?)null,
110111
children = childrenIds,
111112
componentTypes = componentTypes,
112113
path = GameObjectLookup.GetGameObjectPath(go)
@@ -173,7 +174,7 @@ public static object HandleCommand(JObject @params)
173174
componentData.Add(new
174175
{
175176
typeName = component.GetType().FullName,
176-
instanceID = component.GetInstanceID()
177+
instanceID = component.GetInstanceIDCompat()
177178
});
178179
}
179180
}

MCPForUnity/Editor/Tools/Cameras/CameraConfigure.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Newtonsoft.Json.Linq;
55
using UnityEditor;
66
using UnityEngine;
7+
using MCPForUnity.Runtime.Helpers;
78

89
namespace MCPForUnity.Editor.Tools.Cameras
910
{
@@ -36,7 +37,7 @@ internal static object SetBasicCameraTarget(JObject @params)
3637
{
3738
success = true,
3839
message = $"Camera '{go.name}' now looking at '{target.name}'.",
39-
data = new { instanceID = go.GetInstanceID() }
40+
data = new { instanceID = go.GetInstanceIDCompat() }
4041
};
4142
}
4243

@@ -65,7 +66,7 @@ internal static object SetBasicCameraLens(JObject @params)
6566
{
6667
success = true,
6768
message = $"Lens properties set on Camera '{go.name}'.",
68-
data = new { instanceID = go.GetInstanceID() }
69+
data = new { instanceID = go.GetInstanceIDCompat() }
6970
};
7071
}
7172

@@ -88,7 +89,7 @@ internal static object SetBasicCameraPriority(JObject @params)
8889
{
8990
success = true,
9091
message = $"Camera '{go.name}' depth set to {depth}.",
91-
data = new { instanceID = go.GetInstanceID(), depth }
92+
data = new { instanceID = go.GetInstanceIDCompat(), depth }
9293
};
9394
}
9495

@@ -116,7 +117,7 @@ internal static object SetCinemachineTarget(JObject @params)
116117
{
117118
success = true,
118119
message = $"Targets set on CinemachineCamera '{cmCamera.gameObject.name}'.",
119-
data = new { instanceID = cmCamera.gameObject.GetInstanceID() }
120+
data = new { instanceID = cmCamera.gameObject.GetInstanceIDCompat() }
120121
};
121122
}
122123

@@ -147,7 +148,7 @@ internal static object SetCinemachineLens(JObject @params)
147148
{
148149
success = true,
149150
message = $"Lens properties set on CinemachineCamera '{cmCamera.gameObject.name}'.",
150-
data = new { instanceID = cmCamera.gameObject.GetInstanceID() }
151+
data = new { instanceID = cmCamera.gameObject.GetInstanceIDCompat() }
151152
};
152153
}
153154

@@ -181,7 +182,7 @@ internal static object SetCinemachinePriority(JObject @params)
181182
{
182183
success = true,
183184
message = $"Priority set to {priority} on CinemachineCamera '{cmCamera.gameObject.name}'.",
184-
data = new { instanceID = cmCamera.gameObject.GetInstanceID(), priority }
185+
data = new { instanceID = cmCamera.gameObject.GetInstanceIDCompat(), priority }
185186
};
186187
}
187188

@@ -218,7 +219,7 @@ internal static object SetBody(JObject @params)
218219
{
219220
success = true,
220221
message = $"Body configured on CinemachineCamera '{go.name}'.",
221-
data = new { instanceID = go.GetInstanceID(), body = bodyComponent.GetType().Name }
222+
data = new { instanceID = go.GetInstanceIDCompat(), body = bodyComponent.GetType().Name }
222223
};
223224
}
224225

@@ -253,7 +254,7 @@ internal static object SetAim(JObject @params)
253254
{
254255
success = true,
255256
message = $"Aim configured on CinemachineCamera '{go.name}'.",
256-
data = new { instanceID = go.GetInstanceID(), aim = aimComponent.GetType().Name }
257+
data = new { instanceID = go.GetInstanceIDCompat(), aim = aimComponent.GetType().Name }
257258
};
258259
}
259260

@@ -288,7 +289,7 @@ internal static object SetNoise(JObject @params)
288289
message = added
289290
? $"Added noise to CinemachineCamera '{go.name}'."
290291
: $"Noise configured on CinemachineCamera '{go.name}'.",
291-
data = new { instanceID = go.GetInstanceID(), added }
292+
data = new { instanceID = go.GetInstanceIDCompat(), added }
292293
};
293294
}
294295

@@ -320,7 +321,7 @@ internal static object AddExtension(JObject @params)
320321
{
321322
success = true,
322323
message = $"Extension '{extTypeName}' added to CinemachineCamera '{go.name}'.",
323-
data = new { instanceID = go.GetInstanceID(), extensionType = extTypeName }
324+
data = new { instanceID = go.GetInstanceIDCompat(), extensionType = extTypeName }
324325
};
325326
}
326327

@@ -351,7 +352,7 @@ internal static object RemoveExtension(JObject @params)
351352
{
352353
success = true,
353354
message = $"Extension '{extTypeName}' removed from CinemachineCamera '{go.name}'.",
354-
data = new { instanceID = go.GetInstanceID() }
355+
data = new { instanceID = go.GetInstanceIDCompat() }
355356
};
356357
}
357358

0 commit comments

Comments
 (0)