unity-mcp/UnityMcpBridge/Editor/Setup/SetupWizard.cs

151 lines
4.8 KiB
C#
Raw Normal View History

feat: Unity Asset Store compliance with post-installation dependency setup (#281) * feat: implement Unity Asset Store compliance with post-installation dependency setup - Remove bundled Python dependencies from Unity package - Add comprehensive 6-step setup wizard with auto-trigger on first import - Implement cross-platform dependency detection (Windows, macOS, Linux) - Add integrated MCP client configuration within setup process - Create production-ready menu structure with clean UI/UX - Ensure complete end-to-end setup requiring no additional configuration - Add comprehensive error handling and recovery mechanisms This implementation ensures Asset Store compliance while maintaining full functionality through guided user setup. Users are left 100% ready to use MCP after completing the setup wizard. * refactor: improve Asset Store compliance implementation with production-ready setup - Remove automatic installation attempts on package import - Always show setup wizard on package install/reinstall - Integrate MCP client configuration as part of setup wizard process - Ensure MCP client config window remains accessible via menu - Remove testing components for production readiness - Replace automatic installation with manual guidance only - Add complete 4-step setup flow: Welcome → Dependencies → Installation Guide → Client Configuration → Complete - Improve user experience with clear instructions and accessible client management * feat: add comprehensive dependency requirement warnings - Add critical warnings throughout setup wizard that package cannot function without dependencies - Update package.json description to clearly state manual dependency installation requirement - Prevent setup completion if dependencies are missing - Enhance skip setup warning to emphasize package will be non-functional - Add error messages explaining consequences of missing dependencies - Update menu item to indicate setup wizard is required - Ensure users understand package is completely non-functional without proper dependency installation * refactor: simplify setup wizard for production BREAKING: Reduced setup wizard from 5 steps to 3 streamlined steps: - Step 1: Setup (welcome + dependency check + installation guide) - Step 2: Configure (client configuration with direct access to full settings) - Step 3: Complete (final status and quick access to resources) Simplifications: - Consolidated UI components with DRY helper methods (DrawSectionTitle, DrawSuccessStatus, DrawErrorStatus) - Simplified dependency status display with clean icons and essential info - Removed complex state management - using simple EditorPrefs instead - Removed unused InstallationOrchestrator and SetupState classes - Streamlined client configuration to direct users to full settings window - Simplified navigation with back/skip/next buttons - Reduced code complexity while maintaining solid principles Results: - 40% less code while maintaining all functionality - Cleaner, more intuitive user flow - Faster setup process with fewer clicks - Production-ready simplicity - Easier maintenance and debugging * fix: add missing using statement for DependencyCheckResult Add missing 'using MCPForUnity.Editor.Dependencies.Models;' to resolve DependencyCheckResult type reference in SetupWizard.cs * refactor: optimize dependency checks and remove dead code * fix: remove unused DrawInstallationProgressStep method Removes leftover method that references deleted _isInstalling and _installationStatus fields, fixing compilation errors. * feat: improve setup wizard UX and add real client configuration 1. Remove dependency mentions from package.json description 2. Only show dependency warnings when dependencies are actually missing 3. Add actual MCP client configuration functionality within the wizard: - Client selection dropdown - Individual client configuration - Claude Code registration/unregistration - Batch configuration for all clients - Manual setup instructions - Real configuration file writing Users can now complete full setup including client configuration without leaving the wizard. * refactor: improve menu text and client restart tip - Remove '(Required)' from Setup Wizard menu item for cleaner appearance - Update tip to reflect that most AI clients auto-detect configuration changes * refactor: simplify client restart tip message * fix: add missing using statement for MCPForUnityEditorWindow Add 'using MCPForUnity.Editor.Windows;' to resolve unresolved symbol error for MCPForUnityEditorWindow in SetupWizard.cs * Format code * Remove unused folders * Same for validators * Same for Setup... * feat: add setup wizard persistence to avoid showing on subsequent imports * fix: update Python version check to support Python 4+ across all platform detectors * refactor: extract common platform detection logic into PlatformDetectorBase class * feat: add configuration helpers for MCP client setup with sophisticated path resolution * fix: add missing override keyword to DetectPython method in platform detectors * fix: update menu item labels for consistent capitalization and naming * fix: standardize "MCP For Unity" capitalization in window titles and dialogs * refactor: update package ID from justinpbarnett to coplaydev across codebase * refactor: remove unused validation and configuration helper methods * refactor: remove unused warnOnLegacyPackageId parameter from TryFindEmbeddedServerSource --------- Co-authored-by: Claude <claude@anthropic.com> Co-authored-by: Marcus Sanatan <msanatan@gmail.com>
2025-10-04 04:43:40 +08:00
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
{
/// <summary>
/// Handles automatic triggering of the setup wizard
/// </summary>
[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;
}
/// <summary>
/// Check if setup wizard should be shown
/// </summary>
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}");
}
}
/// <summary>
/// Show the setup wizard window
/// </summary>
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}");
}
}
/// <summary>
/// Mark setup as completed
/// </summary>
public static void MarkSetupCompleted()
{
EditorPrefs.SetBool(SETUP_COMPLETED_KEY, true);
McpLog.Info("Setup marked as completed");
}
/// <summary>
/// Mark setup as dismissed
/// </summary>
public static void MarkSetupDismissed()
{
EditorPrefs.SetBool(SETUP_DISMISSED_KEY, true);
McpLog.Info("Setup marked as dismissed");
}
/// <summary>
/// Force show setup wizard (for manual invocation)
/// </summary>
[MenuItem("Window/MCP For Unity/Setup Wizard", priority = 1)]
public static void ShowSetupWizardManual()
{
ShowSetupWizard();
}
/// <summary>
/// Check dependencies and show status
/// </summary>
[MenuItem("Window/MCP For Unity/Check Dependencies", priority = 3)]
public static void CheckDependencies()
{
var result = DependencyManager.CheckAllDependencies();
if (!result.IsSystemReady)
{
bool showWizard = EditorUtility.DisplayDialog(
"MCP for Unity - Dependencies",
$"System Status: {result.Summary}\n\nWould you like to open the Setup Wizard?",
"Open Setup Wizard",
"Close"
);
if (showWizard)
{
ShowSetupWizard(result);
}
}
else
{
EditorUtility.DisplayDialog(
"MCP for Unity - Dependencies",
"✓ All dependencies are available and ready!\n\nMCP for Unity is ready to use.",
"OK"
);
}
}
/// <summary>
/// Open MCP Client Configuration window
/// </summary>
[MenuItem("Window/MCP For Unity/Open MCP Window", priority = 4)]
public static void OpenClientConfiguration()
{
Windows.MCPForUnityEditorWindow.ShowWindow();
}
}
}