/* ┌──────────────────────────────────────────────────────────────────┐ │ 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 System; using System.Collections.Generic; using System.ComponentModel; using System.Text.Json.Serialization; using com.IvanMurzak.McpPlugin; using com.IvanMurzak.ReflectorNet.Model; using AIGD; using System.Linq; using UnityEditor; using UnityEngine; namespace AIGD { public class SelectionData { [Description("Returns the actual game object selection. Includes Prefabs, non-modifiable objects.")] public GameObjectRef[]? GameObjects { get; set; } [Description("Returns the top level selection, excluding Prefabs.")] public ComponentRef[]? Transforms { get; set; } [Description("The actual unfiltered selection from the Scene returned as instance ids instead of objects.")] public int[]? InstanceIDs { get; set; } [Description("Returns the guids of the selected assets.")] public string[]? AssetGUIDs { get; set; } [Description("Returns the active game object. (The one shown in the inspector).")] public GameObjectRef? ActiveGameObject { get; set; } [Description("Returns the instanceID of the actual object selection. Includes Prefabs, non-modifiable objects")] public int ActiveInstanceID { get; set; } [Description("Returns the actual object selection. Includes Prefabs, non-modifiable objects.")] public ObjectRef? ActiveObject { get; set; } [Description("Returns the active transform. (The one shown in the inspector).")] public ComponentRef? ActiveTransform { get; set; } public static SelectionData FromSelection() { return new SelectionData { GameObjects = Selection.gameObjects?.Select(go => new GameObjectRef(go)).ToArray(), Transforms = Selection.transforms?.Select(t => new ComponentRef(t)).ToArray(), #if UNITY_6000_3_OR_NEWER InstanceIDs = Selection.entityIds.Select(x => (int)x).ToArray(), #else InstanceIDs = Selection.instanceIDs, #endif AssetGUIDs = Selection.assetGUIDs, ActiveGameObject = new GameObjectRef(Selection.activeGameObject), #if UNITY_6000_3_OR_NEWER ActiveInstanceID = (int)Selection.activeEntityId, #else ActiveInstanceID = Selection.activeInstanceID, #endif ActiveObject = new ObjectRef(Selection.activeObject), ActiveTransform = new ComponentRef(Selection.activeTransform) }; } } } #endif