using System; using MCPForUnity.Editor.Dependencies; using MCPForUnity.Editor.Dependencies.Models; using MCPForUnity.Editor.Helpers; using MCPForUnity.Editor.Windows; using MCPForUnity.Editor.Constants; using UnityEditor; using UnityEngine; namespace MCPForUnity.Editor.Setup { /// /// Handles automatic triggering of the MCP setup window and exposes menu entry points /// [InitializeOnLoad] public static class SetupWindowService { private const string SETUP_COMPLETED_KEY = EditorPrefKeys.SetupCompleted; private const string SETUP_DISMISSED_KEY = EditorPrefKeys.SetupDismissed; private static bool _hasCheckedThisSession = false; static SetupWindowService() { // Skip in batch mode if (Application.isBatchMode) return; // Show Setup Window on package import EditorApplication.delayCall += CheckSetupNeeded; } /// /// Check if Setup Window should be shown /// private static void CheckSetupNeeded() { if (_hasCheckedThisSession) return; _hasCheckedThisSession = true; try { // Check if setup was already completed or dismissed in previous sessions bool setupCompleted = EditorPrefs.GetBool(SETUP_COMPLETED_KEY, false); bool setupDismissed = EditorPrefs.GetBool(SETUP_DISMISSED_KEY, false); // Only show Setup Window if it hasn't been completed or dismissed before if (!(setupCompleted || setupDismissed)) { McpLog.Info("Package imported - showing Setup Window", always: false); var dependencyResult = DependencyManager.CheckAllDependencies(); EditorApplication.delayCall += () => ShowSetupWindow(dependencyResult); } else { McpLog.Info("Setup Window skipped - previously completed or dismissed", always: false); } } catch (Exception ex) { McpLog.Error($"Error checking setup status: {ex.Message}"); } } /// /// Show the setup window /// public static void ShowSetupWindow(DependencyCheckResult dependencyResult = null) { try { dependencyResult ??= DependencyManager.CheckAllDependencies(); MCPSetupWindow.ShowWindow(dependencyResult); } catch (Exception ex) { McpLog.Error($"Error showing setup window: {ex.Message}"); } } /// /// Mark setup as completed /// public static void MarkSetupCompleted() { EditorPrefs.SetBool(SETUP_COMPLETED_KEY, true); McpLog.Info("Setup marked as completed"); } /// /// Mark setup as dismissed /// public static void MarkSetupDismissed() { EditorPrefs.SetBool(SETUP_DISMISSED_KEY, true); McpLog.Info("Setup marked as dismissed"); } } }