Refactor configuration handling in UnityMcpEditorWindow to streamline JSON serialization and improve client type management
parent
48a865d386
commit
a880bf485b
|
|
@ -409,8 +409,13 @@ namespace UnityMcpBridge.Editor.Windows
|
||||||
string pythonDir = FindPackagePythonDirectory();
|
string pythonDir = FindPackagePythonDirectory();
|
||||||
string manualConfigJson;
|
string manualConfigJson;
|
||||||
|
|
||||||
if (mcpClient.mcpType == McpTypes.VSCode)
|
// Create common JsonSerializerSettings
|
||||||
|
JsonSerializerSettings jsonSettings = new() { Formatting = Formatting.Indented };
|
||||||
|
|
||||||
|
// Use switch statement to handle different client types
|
||||||
|
switch (mcpClient.mcpType)
|
||||||
{
|
{
|
||||||
|
case McpTypes.VSCode:
|
||||||
// Create VSCode-specific configuration with proper format
|
// Create VSCode-specific configuration with proper format
|
||||||
var vscodeConfig = new
|
var vscodeConfig = new
|
||||||
{
|
{
|
||||||
|
|
@ -426,12 +431,10 @@ namespace UnityMcpBridge.Editor.Windows
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
JsonSerializerSettings jsonSettings = new() { Formatting = Formatting.Indented };
|
|
||||||
manualConfigJson = JsonConvert.SerializeObject(vscodeConfig, jsonSettings);
|
manualConfigJson = JsonConvert.SerializeObject(vscodeConfig, jsonSettings);
|
||||||
}
|
break;
|
||||||
else
|
|
||||||
{
|
default:
|
||||||
// Create standard MCP configuration for other clients
|
// Create standard MCP configuration for other clients
|
||||||
McpConfig jsonConfig = new()
|
McpConfig jsonConfig = new()
|
||||||
{
|
{
|
||||||
|
|
@ -444,9 +447,8 @@ namespace UnityMcpBridge.Editor.Windows
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
JsonSerializerSettings jsonSettings = new() { Formatting = Formatting.Indented };
|
|
||||||
manualConfigJson = JsonConvert.SerializeObject(jsonConfig, jsonSettings);
|
manualConfigJson = JsonConvert.SerializeObject(jsonConfig, jsonSettings);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ManualConfigEditorWindow.ShowWindow(configPath, manualConfigJson, mcpClient);
|
ManualConfigEditorWindow.ShowWindow(configPath, manualConfigJson, mcpClient);
|
||||||
|
|
@ -642,7 +644,10 @@ namespace UnityMcpBridge.Editor.Windows
|
||||||
string configJson = File.ReadAllText(configPath);
|
string configJson = File.ReadAllText(configPath);
|
||||||
string pythonDir = ServerInstaller.GetServerPath();
|
string pythonDir = ServerInstaller.GetServerPath();
|
||||||
|
|
||||||
// Use switch statement to handle different client types
|
// Use switch statement to handle different client types, extracting common logic
|
||||||
|
string[] args = null;
|
||||||
|
bool configExists = false;
|
||||||
|
|
||||||
switch (mcpClient.mcpType)
|
switch (mcpClient.mcpType)
|
||||||
{
|
{
|
||||||
case McpTypes.VSCode:
|
case McpTypes.VSCode:
|
||||||
|
|
@ -651,21 +656,8 @@ namespace UnityMcpBridge.Editor.Windows
|
||||||
if (config?.mcp?.servers?.unityMCP != null)
|
if (config?.mcp?.servers?.unityMCP != null)
|
||||||
{
|
{
|
||||||
// Extract args from VSCode config format
|
// Extract args from VSCode config format
|
||||||
var args = config.mcp.servers.unityMCP.args.ToObject<string[]>();
|
args = config.mcp.servers.unityMCP.args.ToObject<string[]>();
|
||||||
|
configExists = true;
|
||||||
if (pythonDir != null &&
|
|
||||||
Array.Exists(args, new Predicate<string>(arg => arg.Contains(pythonDir, StringComparison.Ordinal))))
|
|
||||||
{
|
|
||||||
mcpClient.SetStatus(McpStatus.Configured);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mcpClient.SetStatus(McpStatus.IncorrectPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mcpClient.SetStatus(McpStatus.MissingConfig);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -675,11 +667,17 @@ namespace UnityMcpBridge.Editor.Windows
|
||||||
|
|
||||||
if (standardConfig?.mcpServers?.unityMCP != null)
|
if (standardConfig?.mcpServers?.unityMCP != null)
|
||||||
{
|
{
|
||||||
if (pythonDir != null
|
args = standardConfig.mcpServers.unityMCP.args;
|
||||||
&& Array.Exists(
|
configExists = true;
|
||||||
standardConfig.mcpServers.unityMCP.args,
|
}
|
||||||
arg => arg.Contains(pythonDir, StringComparison.Ordinal)
|
break;
|
||||||
))
|
}
|
||||||
|
|
||||||
|
// Common logic for checking configuration status
|
||||||
|
if (configExists)
|
||||||
|
{
|
||||||
|
if (pythonDir != null &&
|
||||||
|
Array.Exists(args, arg => arg.Contains(pythonDir, StringComparison.Ordinal)))
|
||||||
{
|
{
|
||||||
mcpClient.SetStatus(McpStatus.Configured);
|
mcpClient.SetStatus(McpStatus.Configured);
|
||||||
}
|
}
|
||||||
|
|
@ -692,8 +690,6 @@ namespace UnityMcpBridge.Editor.Windows
|
||||||
{
|
{
|
||||||
mcpClient.SetStatus(McpStatus.MissingConfig);
|
mcpClient.SetStatus(McpStatus.MissingConfig);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue