/* ┌──────────────────────────────────────────────────────────────────┐ │ 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 using System; using System.Collections.Generic; using System.Diagnostics; using com.IvanMurzak.McpPlugin.Common.Utils; using com.IvanMurzak.ReflectorNet; using com.IvanMurzak.Unity.MCP.Editor.Utils; using com.IvanMurzak.Unity.MCP.Utils; using Microsoft.Extensions.Logging; using UnityEditor; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; namespace com.IvanMurzak.Unity.MCP.Editor.UI { /// /// An editor window for testing object serialization using the MCP reflector. /// public class SerializationCheckWindow : McpWindowBase { private static readonly string[] _windowUxmlPaths = EditorAssetLoader.GetEditorAssetPaths("Editor/UI/uxml/SerializationCheckWindow.uxml"); private static readonly string[] _windowUssPaths = EditorAssetLoader.GetEditorAssetPaths("Editor/UI/uss/SerializationCheckWindow.uss"); protected override string[] WindowUxmlPaths => _windowUxmlPaths; protected override string[] WindowUssPaths => _windowUssPaths; protected override string WindowTitle => "Serialization Check"; private ObjectField? targetField; private Toggle? recursiveToggle; private Button? serializeButton; private Button? copyButton; private Label? outputHeader; private ListView? outputList; private readonly List outputLines = new(); private string fullOutputText = string.Empty; public static void ShowWindow() { var window = GetWindow(utility: false, "Serialization Check", focus: true); window.SetupWindowWithIcon(); window.minSize = new Vector2(400, 500); window.Show(); } protected override void OnGUICreated(VisualElement root) { BindUI(root); } private void BindUI(VisualElement root) { // Bind target object field targetField = root.Q("target-field"); if (targetField == null) throw new InvalidOperationException("target-field ObjectField not found in UXML"); targetField.objectType = typeof(UnityEngine.Object); // Bind recursive toggle recursiveToggle = root.Q("recursive-toggle"); if (recursiveToggle == null) throw new InvalidOperationException("recursive-toggle Toggle not found in UXML"); // Bind serialize button serializeButton = root.Q