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
3 changes: 2 additions & 1 deletion MCPForUnity/Editor/Helpers/ComponentOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.Events;
using MCPForUnity.Runtime.Helpers;

namespace MCPForUnity.Editor.Helpers
{
Expand Down Expand Up @@ -977,7 +978,7 @@ private static long GetSpriteFileId(Sprite sprite)
}
catch (Exception ex)
{
McpLog.Warn($"Failed to get fileID for sprite '{sprite.name}' (instanceID={sprite.GetInstanceID()}): {ex.Message}");
McpLog.Warn($"Failed to get fileID for sprite '{sprite.name}' (instanceID={sprite.GetInstanceIDCompat()}): {ex.Message}");
return 0;
}
}
Expand Down
15 changes: 8 additions & 7 deletions MCPForUnity/Editor/Helpers/GameObjectLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
using MCPForUnity.Runtime.Helpers;

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

return matching.Select(go => go.GetInstanceID());
return matching.Select(go => go.GetInstanceIDCompat());
}

private static IEnumerable<int> SearchByPath(string path, bool includeInactive)
Expand All @@ -170,7 +171,7 @@ private static IEnumerable<int> SearchByPath(string path, bool includeInactive)
{
if (MatchesPath(go, path))
{
yield return go.GetInstanceID();
yield return go.GetInstanceIDCompat();
}
}
yield break;
Expand All @@ -187,7 +188,7 @@ private static IEnumerable<int> SearchByPath(string path, bool includeInactive)
{
if (MatchesPath(go, path))
{
yield return go.GetInstanceID();
yield return go.GetInstanceIDCompat();
}
}
}
Expand All @@ -197,7 +198,7 @@ private static IEnumerable<int> SearchByPath(string path, bool includeInactive)
var found = GameObject.Find(path);
if (found != null)
{
yield return found.GetInstanceID();
yield return found.GetInstanceIDCompat();
}
}
}
Expand Down Expand Up @@ -230,7 +231,7 @@ private static IEnumerable<int> SearchByTag(string tag, bool includeInactive, in

foreach (var go in results)
{
yield return go.GetInstanceID();
yield return go.GetInstanceIDCompat();
}
}

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

foreach (var go in matching)
{
yield return go.GetInstanceID();
yield return go.GetInstanceIDCompat();
}
}

Expand All @@ -274,7 +275,7 @@ private static IEnumerable<int> SearchByComponent(string componentTypeName, bool
{
if (go.GetComponent(componentType) != null)
{
yield return go.GetInstanceID();
yield return go.GetInstanceIDCompat();
count++;

if (maxResults > 0 && count >= maxResults)
Expand Down
27 changes: 14 additions & 13 deletions MCPForUnity/Editor/Helpers/GameObjectSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEngine;
using MCPForUnity.Runtime.Helpers;

namespace MCPForUnity.Editor.Helpers
{
Expand All @@ -28,7 +29,7 @@ public static object GetGameObjectData(GameObject go)
return new
{
name = go.name,
instanceID = go.GetInstanceID(),
instanceID = go.GetInstanceIDCompat(),
tag = go.tag,
layer = go.layer,
activeSelf = go.activeSelf,
Expand Down Expand Up @@ -88,7 +89,7 @@ public static object GetGameObjectData(GameObject go)
z = go.transform.right.z,
},
},
parentInstanceID = go.transform.parent?.gameObject.GetInstanceID() ?? 0, // 0 if no parent
parentInstanceID = go.transform.parent?.gameObject.GetInstanceIDCompat() ?? 0, // 0 if no parent
// Optionally include components, but can be large
// components = go.GetComponents<Component>().Select(c => GetComponentData(c)).ToList()
// Or just component names:
Expand Down Expand Up @@ -144,7 +145,7 @@ private static Dictionary<string, object> SerializeAssetReference(UnityEngine.Ob
var result = new Dictionary<string, object>
{
{ "name", obj.name },
{ "instanceID", obj.GetInstanceID() }
{ "instanceID", obj.GetInstanceIDCompat() }
};

if (includeAssetPath)
Expand All @@ -164,7 +165,7 @@ private static Dictionary<string, object> SerializeAssetReference(UnityEngine.Ob
public static object GetComponentData(Component c, bool includeNonPublicSerializedFields = true)
{
// --- Add Early Logging ---
// McpLog.Info($"[GetComponentData] Starting for component: {c?.GetType()?.FullName ?? "null"} (ID: {c?.GetInstanceID() ?? 0})");
// McpLog.Info($"[GetComponentData] Starting for component: {c?.GetType()?.FullName ?? "null"} (ID: {c?.GetInstanceIDCompat() ?? 0})");
// --- End Early Logging ---

if (c == null) return null;
Expand All @@ -174,11 +175,11 @@ public static object GetComponentData(Component c, bool includeNonPublicSerializ
if (componentType == typeof(Transform))
{
Transform tr = c as Transform;
// McpLog.Info($"[GetComponentData] Manually serializing Transform (ID: {tr.GetInstanceID()})");
// McpLog.Info($"[GetComponentData] Manually serializing Transform (ID: {tr.GetInstanceIDCompat()})");
return new Dictionary<string, object>
{
{ "typeName", componentType.FullName },
{ "instanceID", tr.GetInstanceID() },
{ "instanceID", tr.GetInstanceIDCompat() },
// Manually extract known-safe properties. Avoid Quaternion 'rotation' and 'lossyScale'.
{ "position", CreateTokenFromValue(tr.position, typeof(Vector3))?.ToObject<object>() ?? new JObject() },
{ "localPosition", CreateTokenFromValue(tr.localPosition, typeof(Vector3))?.ToObject<object>() ?? new JObject() },
Expand All @@ -188,13 +189,13 @@ public static object GetComponentData(Component c, bool includeNonPublicSerializ
{ "right", CreateTokenFromValue(tr.right, typeof(Vector3))?.ToObject<object>() ?? new JObject() },
{ "up", CreateTokenFromValue(tr.up, typeof(Vector3))?.ToObject<object>() ?? new JObject() },
{ "forward", CreateTokenFromValue(tr.forward, typeof(Vector3))?.ToObject<object>() ?? new JObject() },
{ "parentInstanceID", tr.parent?.gameObject.GetInstanceID() ?? 0 },
{ "rootInstanceID", tr.root?.gameObject.GetInstanceID() ?? 0 },
{ "parentInstanceID", tr.parent?.gameObject.GetInstanceIDCompat() ?? 0 },
{ "rootInstanceID", tr.root?.gameObject.GetInstanceIDCompat() ?? 0 },
{ "childCount", tr.childCount },
// Include standard Object/Component properties
{ "name", tr.name },
{ "tag", tr.tag },
{ "gameObjectInstanceID", tr.gameObject?.GetInstanceID() ?? 0 }
{ "gameObjectInstanceID", tr.gameObject?.GetInstanceIDCompat() ?? 0 }
};
}
// --- End Special handling for Transform ---
Expand Down Expand Up @@ -233,7 +234,7 @@ public static object GetComponentData(Component c, bool includeNonPublicSerializ
{ "enabled", () => cam.enabled },
{ "name", () => cam.name },
{ "tag", () => cam.tag },
{ "gameObject", () => new { name = cam.gameObject.name, instanceID = cam.gameObject.GetInstanceID() } }
{ "gameObject", () => new { name = cam.gameObject.name, instanceID = cam.gameObject.GetInstanceIDCompat() } }
};

foreach (var prop in safeProperties)
Expand All @@ -256,7 +257,7 @@ public static object GetComponentData(Component c, bool includeNonPublicSerializ
return new Dictionary<string, object>
{
{ "typeName", componentType.FullName },
{ "instanceID", cam.GetInstanceID() },
{ "instanceID", cam.GetInstanceIDCompat() },
{ "properties", cameraProperties }
};
}
Expand Down Expand Up @@ -322,7 +323,7 @@ public static object GetComponentData(Component c, bool includeNonPublicSerializ
return new Dictionary<string, object>
{
{ "typeName", componentType.FullName },
{ "instanceID", c.GetInstanceID() },
{ "instanceID", c.GetInstanceIDCompat() },
{ "properties", uiDocProperties }
};
}
Expand All @@ -331,7 +332,7 @@ public static object GetComponentData(Component c, bool includeNonPublicSerializ
var data = new Dictionary<string, object>
{
{ "typeName", componentType.FullName },
{ "instanceID", c.GetInstanceID() }
{ "instanceID", c.GetInstanceIDCompat() }
};

// --- Get Cached or Generate Metadata (using new cache key) ---
Expand Down
7 changes: 4 additions & 3 deletions MCPForUnity/Editor/Resources/Editor/Selection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using MCPForUnity.Editor.Helpers;
using Newtonsoft.Json.Linq;
using UnityEditor;
using MCPForUnity.Runtime.Helpers;

namespace MCPForUnity.Editor.Resources.Editor
{
Expand All @@ -21,21 +22,21 @@ public static object HandleCommand(JObject @params)
activeObject = UnityEditor.Selection.activeObject?.name,
activeGameObject = UnityEditor.Selection.activeGameObject?.name,
activeTransform = UnityEditor.Selection.activeTransform?.name,
activeInstanceID = UnityEditor.Selection.activeObject?.GetInstanceID() ?? 0,
activeInstanceID = UnityEditor.Selection.activeObject?.GetInstanceIDCompat() ?? 0,
count = UnityEditor.Selection.count,
objects = UnityEditor.Selection.objects
.Select(obj => new
{
name = obj?.name,
type = obj?.GetType().FullName,
instanceID = obj?.GetInstanceID()
instanceID = obj?.GetInstanceIDCompat()
})
.ToList(),
gameObjects = UnityEditor.Selection.gameObjects
.Select(go => new
{
name = go?.name,
instanceID = go?.GetInstanceID()
instanceID = go?.GetInstanceIDCompat()
})
.ToList(),
assetGUIDs = UnityEditor.Selection.assetGUIDs
Expand Down
3 changes: 2 additions & 1 deletion MCPForUnity/Editor/Resources/Editor/Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEngine;
using MCPForUnity.Runtime.Helpers;

namespace MCPForUnity.Editor.Resources.Editor
{
Expand Down Expand Up @@ -39,7 +40,7 @@ public static object HandleCommand(JObject @params)
width = window.position.width,
height = window.position.height
},
instanceID = window.GetInstanceID()
instanceID = window.GetInstanceIDCompat()
});
}
catch (Exception ex)
Expand Down
9 changes: 5 additions & 4 deletions MCPForUnity/Editor/Resources/Scene/GameObjectResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEngine;
using MCPForUnity.Runtime.Helpers;

namespace MCPForUnity.Editor.Resources.Scene
{
Expand Down Expand Up @@ -84,12 +85,12 @@ public static object SerializeGameObject(GameObject go)
var childrenIds = new List<int>();
foreach (Transform child in transform)
{
childrenIds.Add(child.gameObject.GetInstanceID());
childrenIds.Add(child.gameObject.GetInstanceIDCompat());
}

return new
{
instanceID = go.GetInstanceID(),
instanceID = go.GetInstanceIDCompat(),
name = go.name,
tag = go.tag,
layer = go.layer,
Expand All @@ -106,7 +107,7 @@ public static object SerializeGameObject(GameObject go)
scale = SerializeVector3(transform.localScale),
lossyScale = SerializeVector3(transform.lossyScale)
},
parent = transform.parent != null ? transform.parent.gameObject.GetInstanceID() : (int?)null,
parent = transform.parent != null ? transform.parent.gameObject.GetInstanceIDCompat() : (int?)null,
children = childrenIds,
componentTypes = componentTypes,
path = GameObjectLookup.GetGameObjectPath(go)
Expand Down Expand Up @@ -173,7 +174,7 @@ public static object HandleCommand(JObject @params)
componentData.Add(new
{
typeName = component.GetType().FullName,
instanceID = component.GetInstanceID()
instanceID = component.GetInstanceIDCompat()
});
}
}
Expand Down
23 changes: 12 additions & 11 deletions MCPForUnity/Editor/Tools/Cameras/CameraConfigure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEngine;
using MCPForUnity.Runtime.Helpers;

namespace MCPForUnity.Editor.Tools.Cameras
{
Expand Down Expand Up @@ -36,7 +37,7 @@ internal static object SetBasicCameraTarget(JObject @params)
{
success = true,
message = $"Camera '{go.name}' now looking at '{target.name}'.",
data = new { instanceID = go.GetInstanceID() }
data = new { instanceID = go.GetInstanceIDCompat() }
};
}

Expand Down Expand Up @@ -65,7 +66,7 @@ internal static object SetBasicCameraLens(JObject @params)
{
success = true,
message = $"Lens properties set on Camera '{go.name}'.",
data = new { instanceID = go.GetInstanceID() }
data = new { instanceID = go.GetInstanceIDCompat() }
};
}

Expand All @@ -88,7 +89,7 @@ internal static object SetBasicCameraPriority(JObject @params)
{
success = true,
message = $"Camera '{go.name}' depth set to {depth}.",
data = new { instanceID = go.GetInstanceID(), depth }
data = new { instanceID = go.GetInstanceIDCompat(), depth }
};
}

Expand Down Expand Up @@ -116,7 +117,7 @@ internal static object SetCinemachineTarget(JObject @params)
{
success = true,
message = $"Targets set on CinemachineCamera '{cmCamera.gameObject.name}'.",
data = new { instanceID = cmCamera.gameObject.GetInstanceID() }
data = new { instanceID = cmCamera.gameObject.GetInstanceIDCompat() }
};
}

Expand Down Expand Up @@ -147,7 +148,7 @@ internal static object SetCinemachineLens(JObject @params)
{
success = true,
message = $"Lens properties set on CinemachineCamera '{cmCamera.gameObject.name}'.",
data = new { instanceID = cmCamera.gameObject.GetInstanceID() }
data = new { instanceID = cmCamera.gameObject.GetInstanceIDCompat() }
};
}

Expand Down Expand Up @@ -181,7 +182,7 @@ internal static object SetCinemachinePriority(JObject @params)
{
success = true,
message = $"Priority set to {priority} on CinemachineCamera '{cmCamera.gameObject.name}'.",
data = new { instanceID = cmCamera.gameObject.GetInstanceID(), priority }
data = new { instanceID = cmCamera.gameObject.GetInstanceIDCompat(), priority }
};
}

Expand Down Expand Up @@ -218,7 +219,7 @@ internal static object SetBody(JObject @params)
{
success = true,
message = $"Body configured on CinemachineCamera '{go.name}'.",
data = new { instanceID = go.GetInstanceID(), body = bodyComponent.GetType().Name }
data = new { instanceID = go.GetInstanceIDCompat(), body = bodyComponent.GetType().Name }
};
}

Expand Down Expand Up @@ -253,7 +254,7 @@ internal static object SetAim(JObject @params)
{
success = true,
message = $"Aim configured on CinemachineCamera '{go.name}'.",
data = new { instanceID = go.GetInstanceID(), aim = aimComponent.GetType().Name }
data = new { instanceID = go.GetInstanceIDCompat(), aim = aimComponent.GetType().Name }
};
}

Expand Down Expand Up @@ -288,7 +289,7 @@ internal static object SetNoise(JObject @params)
message = added
? $"Added noise to CinemachineCamera '{go.name}'."
: $"Noise configured on CinemachineCamera '{go.name}'.",
data = new { instanceID = go.GetInstanceID(), added }
data = new { instanceID = go.GetInstanceIDCompat(), added }
};
}

Expand Down Expand Up @@ -320,7 +321,7 @@ internal static object AddExtension(JObject @params)
{
success = true,
message = $"Extension '{extTypeName}' added to CinemachineCamera '{go.name}'.",
data = new { instanceID = go.GetInstanceID(), extensionType = extTypeName }
data = new { instanceID = go.GetInstanceIDCompat(), extensionType = extTypeName }
};
}

Expand Down Expand Up @@ -351,7 +352,7 @@ internal static object RemoveExtension(JObject @params)
{
success = true,
message = $"Extension '{extTypeName}' removed from CinemachineCamera '{go.name}'.",
data = new { instanceID = go.GetInstanceID() }
data = new { instanceID = go.GetInstanceIDCompat() }
};
}

Expand Down
Loading