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

160 lines
5.1 KiB
C#
Raw Normal View History

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>
New UI and work without MCP server embedded (#313) * First pass at new UI * Point to new UI * Refactor: New Service-Based MCP Editor Window Architecture We separate the business logic from the UI rendering of the new editor window with new services. I didn't go full Dependency Injection, not sure if I want to add those deps to the install as yet, but service location is fairly straightforward. Some differences with the old window: - No more Auto-Setup, users will manually decide what they want to do - Removed Python detection warning, we have a setup wizard now - Added explicit path overrides for `uv` and the MCP server itself * style: add flex-shrink and overflow handling to improve UI element scaling * fix: update UI configuration and visibility when client status changes * feat: add menu item to open legacy MCP configuration window * refactor: improve editor window lifecycle handling with proper update subscription * feat: add auto-verification of bridge health when connected * fix: update Claude Code MCP server registration to use lowercase unityMCP name and correct the manual installation instructions * fix: add Claude CLI directory to PATH for node/nvm environments * Clarify how users will see MCP tools * Add a keyboard shortcut to open the window * feat: add server download UI and improve installation status messaging This is needed for the Unity Asset Store, which doesn't have the Python server embedded. * feat: add dynamic asset path detection to support both Package Manager and Asset Store installations * fix: replace unicode emojis with escaped characters in status messages * feat: add server package creation and GitHub release publishing to version bump workflow * fix: add v prefix to server package filename in release workflow * Fix download location * style: improve dropdown and settings layout responsiveness with flex-shrink and max-width * feat: add package.json version detection and refactor path utilities * refactor: simplify imports and use fully qualified names in ServerInstaller.cs * refactor: replace Unity Debug.Log calls with custom McpLog class * fix: extract server files to temp directory before moving to final location * docs: add v6 UI documentation and screenshots with service architecture overview * docs: add new UI Toolkit-based editor window with service architecture and path overrides * feat: improve package path resolution to support Package Manager and Asset Store installations * Change Claude Code's casing back to "UnityMCP" There's no need to break anything as yet * fix: update success dialog text to clarify manual bridge start requirement * refactor: move RefreshDebounce and ManageScriptRefreshHelpers classes inside namespace * feat: add Asset Store fallback path detection for package root lookup * fix: update server installation success message to be more descriptive * refactor: replace Unity Debug.Log calls with custom McpLog utility * fix: add file existence check before opening configuration file * refactor: simplify asset path handling and remove redundant helper namespace references * docs: update code block syntax highlighting in UI changes doc * docs: add code block syntax highlighting for file structure example * feat: import UnityEditor.UIElements namespace for UI components for Unity 2021 compatibility * refactor: rename Python server references to MCP server for consistency * fix: reset client status label color after error state is cleared * Replace the phrase "Python server" with "MCP server" * MInor doc clarification * docs: add path override methods for UV and Claude CLI executables * docs: update service locator registration method name from SetCustomImplementation to Register
2025-10-11 15:08:16 +08:00
[MenuItem("Window/MCP For Unity/Open MCP Window %#m", priority = 4)]
public static void OpenClientConfiguration()
New UI and work without MCP server embedded (#313) * First pass at new UI * Point to new UI * Refactor: New Service-Based MCP Editor Window Architecture We separate the business logic from the UI rendering of the new editor window with new services. I didn't go full Dependency Injection, not sure if I want to add those deps to the install as yet, but service location is fairly straightforward. Some differences with the old window: - No more Auto-Setup, users will manually decide what they want to do - Removed Python detection warning, we have a setup wizard now - Added explicit path overrides for `uv` and the MCP server itself * style: add flex-shrink and overflow handling to improve UI element scaling * fix: update UI configuration and visibility when client status changes * feat: add menu item to open legacy MCP configuration window * refactor: improve editor window lifecycle handling with proper update subscription * feat: add auto-verification of bridge health when connected * fix: update Claude Code MCP server registration to use lowercase unityMCP name and correct the manual installation instructions * fix: add Claude CLI directory to PATH for node/nvm environments * Clarify how users will see MCP tools * Add a keyboard shortcut to open the window * feat: add server download UI and improve installation status messaging This is needed for the Unity Asset Store, which doesn't have the Python server embedded. * feat: add dynamic asset path detection to support both Package Manager and Asset Store installations * fix: replace unicode emojis with escaped characters in status messages * feat: add server package creation and GitHub release publishing to version bump workflow * fix: add v prefix to server package filename in release workflow * Fix download location * style: improve dropdown and settings layout responsiveness with flex-shrink and max-width * feat: add package.json version detection and refactor path utilities * refactor: simplify imports and use fully qualified names in ServerInstaller.cs * refactor: replace Unity Debug.Log calls with custom McpLog class * fix: extract server files to temp directory before moving to final location * docs: add v6 UI documentation and screenshots with service architecture overview * docs: add new UI Toolkit-based editor window with service architecture and path overrides * feat: improve package path resolution to support Package Manager and Asset Store installations * Change Claude Code's casing back to "UnityMCP" There's no need to break anything as yet * fix: update success dialog text to clarify manual bridge start requirement * refactor: move RefreshDebounce and ManageScriptRefreshHelpers classes inside namespace * feat: add Asset Store fallback path detection for package root lookup * fix: update server installation success message to be more descriptive * refactor: replace Unity Debug.Log calls with custom McpLog utility * fix: add file existence check before opening configuration file * refactor: simplify asset path handling and remove redundant helper namespace references * docs: update code block syntax highlighting in UI changes doc * docs: add code block syntax highlighting for file structure example * feat: import UnityEditor.UIElements namespace for UI components for Unity 2021 compatibility * refactor: rename Python server references to MCP server for consistency * fix: reset client status label color after error state is cleared * Replace the phrase "Python server" with "MCP server" * MInor doc clarification * docs: add path override methods for UV and Claude CLI executables * docs: update service locator registration method name from SetCustomImplementation to Register
2025-10-11 15:08:16 +08:00
{
Windows.MCPForUnityEditorWindowNew.ShowWindow();
}
/// <summary>
/// Open legacy MCP Client Configuration window
/// </summary>
[MenuItem("Window/MCP For Unity/Open Legacy MCP Window", priority = 5)]
public static void OpenLegacyClientConfiguration()
{
Windows.MCPForUnityEditorWindow.ShowWindow();
}
}
}