using UnityEditor; using UnityEngine; using LLM.Editor.Core; using LLM.Editor.Client; using System.Threading.Tasks; namespace LLM.Editor.GUI { public class MCPWindow : EditorWindow { private string _promptText = "Create a script named Rotate with a public float for speed. Then, find the 'Racer' model, make a prefab from it, attach the script, and add it to the scene."; private Vector2 _scrollPos; private bool _isRequestInProgress; [MenuItem("Tools/LLM/MCP Assistant")] public static void ShowWindow() { GetWindow("MCP Assistant"); } [MenuItem("Tools/LLM/Print Persistent Data Path")] public static void PrintPersistantPath() { Debug.Log(Application.persistentDataPath); } [MenuItem("Tools/LLM/Print Instance ID (Selected Object)")] public static void PrintInstanceId() { var selection = Selection.activeObject; if (selection != null) { Debug.Log(selection.GetInstanceID()); } } [MenuItem("Tools/LLM/Log object with instance ID")] public static void PrintObjectWithInstanceId() { var obj = EditorUtility.InstanceIDToObject(20404); Debug.Log(obj, obj); } private void OnEnable() { // Subscribe to updates from the executor so the window can repaint CommandExecutor.OnQueueUpdated += Repaint; } private void OnDisable() { CommandExecutor.OnQueueUpdated -= Repaint; } private void OnGUI() { EditorGUILayout.LabelField("LLM Co-Pilot", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); if (SessionManager.HasActiveSession()) { EditorGUILayout.LabelField($"Session: {SessionManager.GetCurrentSessionId()}"); if (GUILayout.Button("End Session")) { SessionManager.EndSession(); } } else { if (GUILayout.Button("Start New Session")) { SessionManager.StartNewSession(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); UnityEngine.GUI.enabled = SessionManager.HasActiveSession() && !_isRequestInProgress; EditorGUILayout.LabelField("Enter your request:"); _promptText = EditorGUILayout.TextArea(_promptText, GUILayout.Height(60)); if (GUILayout.Button(_isRequestInProgress ? "Waiting for response..." : "Send")) { // Fire off the async task _ = SendPromptAsync(); } EditorGUILayout.Space(); UnityEngine.GUI.enabled = !_isRequestInProgress; EditorGUILayout.LabelField("Pending Commands", EditorStyles.boldLabel); _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, EditorStyles.helpBox); if (CommandExecutor.HasPendingCommands()) { var nextCommand = CommandExecutor.GetNextCommand(); EditorGUILayout.LabelField("Next Up: " + nextCommand.commandName); if (GUILayout.Button("Execute Next Command")) { CommandExecutor.ExecuteNextCommand(); } } else { EditorGUILayout.LabelField("No pending commands."); } EditorGUILayout.EndScrollView(); UnityEngine.GUI.enabled = true; } private async Task SendPromptAsync() { _isRequestInProgress = true; Repaint(); await GeminiApiClient.SendPrompt(_promptText); _isRequestInProgress = false; Repaint(); } } }