using System; using MCPForUnity.Editor.Dependencies; using MCPForUnity.Editor.Dependencies.Models; using MCPForUnity.Editor.Helpers; using MCPForUnity.Editor.Windows; using UnityEditor; using UnityEngine; namespace MCPForUnity.Editor.Setup { /// /// Handles automatic triggering of the setup wizard /// [InitializeOnLoad] public static class SetupWizard { private const string SETUP_COMPLETED_KEY = "MCPForUnity.SetupCompleted"; private const string SETUP_DISMISSED_KEY = "MCPForUnity.SetupDismissed"; private static bool _hasCheckedThisSession = false; static SetupWizard() { // Skip in batch mode if (Application.isBatchMode) return; // Show setup wizard on package import EditorApplication.delayCall += CheckSetupNeeded; } /// /// Check if setup wizard 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 wizard if it hasn't been completed or dismissed before if (!(setupCompleted || setupDismissed)) { McpLog.Info("Package imported - showing setup wizard", always: false); var dependencyResult = DependencyManager.CheckAllDependencies(); EditorApplication.delayCall += () => ShowSetupWizard(dependencyResult); } else { McpLog.Info("Setup wizard skipped - previously completed or dismissed", always: false); } } catch (Exception ex) { McpLog.Error($"Error checking setup status: {ex.Message}"); } } /// /// Show the setup wizard window /// public static void ShowSetupWizard(DependencyCheckResult dependencyResult = null) { try { dependencyResult ??= DependencyManager.CheckAllDependencies(); SetupWizardWindow.ShowWindow(dependencyResult); } catch (Exception ex) { McpLog.Error($"Error showing setup wizard: {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"); } } }