using System; using System.Collections.Generic; using Newtonsoft.Json.Linq; namespace UnityMcpBridge.Editor.Tools { /// /// Registry for all MCP command handlers (Refactored Version) /// public static class CommandRegistry { // Maps command names (matching those called from Python via ctx.bridge.unity_editor.HandlerName) // to the corresponding static HandleCommand method in the appropriate tool class. private static readonly Dictionary> _handlers = new() { { "HandleManageScript", ManageScript.HandleCommand }, { "HandleManageScene", ManageScene.HandleCommand }, { "HandleManageEditor", ManageEditor.HandleCommand }, { "HandleManageGameObject", ManageGameObject.HandleCommand }, { "HandleManageAsset", ManageAsset.HandleCommand }, { "HandleReadConsole", ReadConsole.HandleCommand }, { "HandleExecuteMenuItem", ExecuteMenuItem.HandleCommand }, { "HandleManageShader", ManageShader.HandleCommand}, }; /// /// Gets a command handler by name. /// /// Name of the command handler (e.g., "HandleManageAsset"). /// The command handler function if found, null otherwise. public static Func GetHandler(string commandName) { // Use case-insensitive comparison for flexibility, although Python side should be consistent return _handlers.TryGetValue(commandName, out var handler) ? handler : null; // Consider adding logging here if a handler is not found /* if (_handlers.TryGetValue(commandName, out var handler)) { return handler; } else { UnityEngine.Debug.LogError($\"[CommandRegistry] No handler found for command: {commandName}\"); return null; } */ } } }