/* ┌──────────────────────────────────────────────────────────────────┐ │ Author: Ivan Murzak (https://github.com/IvanMurzak) │ │ Repository: GitHub (https://github.com/IvanMurzak/Unity-MCP) │ │ Copyright (c) 2025 Ivan Murzak │ │ Licensed under the Apache License, Version 2.0. │ │ See the LICENSE file in the project root for more information. │ └──────────────────────────────────────────────────────────────────┘ */ #nullable enable #if !UNITY_6000_5_OR_NEWER using com.IvanMurzak.ReflectorNet.Model; using AIGD; namespace com.IvanMurzak.Unity.MCP.Editor.Extensions { public static class ExtensionsSerializedMember { public static bool TryGetInstanceID(this SerializedMember member, out int instanceID) { var reflector = UnityMcpPluginEditor.Instance.Reflector; if (reflector == null) { instanceID = 0; return false; } try { var objectRef = member.GetValue(reflector); if (objectRef != null) { instanceID = objectRef.InstanceID; return true; } } catch { // Ignore exceptions, fallback to instanceID field } try { var fieldValue = member.GetField(ObjectRef.ObjectRefProperty.InstanceID); if (fieldValue != null) { instanceID = fieldValue.GetValue(reflector); return true; } } catch { // Ignore exceptions, fallback to instanceID field } instanceID = 0; return false; } public static bool TryGetGameObjectInstanceID(this SerializedMember member, out int instanceID) { var reflector = UnityMcpPluginEditor.Instance.Reflector; if (reflector == null) { instanceID = 0; return false; } try { var objectRef = member.GetValue(reflector); if (objectRef != null) { instanceID = objectRef.InstanceID; return true; } } catch { // Ignore exceptions, fallback to instanceID field } try { var fieldValue = member.GetField(ObjectRef.ObjectRefProperty.InstanceID); if (fieldValue != null) { instanceID = fieldValue.GetValue(reflector); return true; } } catch { // Ignore exceptions, fallback to instanceID field } instanceID = 0; return false; } } } #endif