added more advanced auto-config setup

main
Justin Barnett 2025-03-18 16:28:22 -04:00
parent 150a39694f
commit 8860a7317c
1 changed files with 64 additions and 20 deletions

View File

@ -417,26 +417,8 @@ public class MCPEditorWindow : EditorWindow
{ {
claudeConfigStatus = "Error: Manual configuration required"; claudeConfigStatus = "Error: Manual configuration required";
// Get the Python directory path that's likely to exist // Get the Python directory path using Package Manager API
string pythonDir = ""; string pythonDir = FindPackagePythonDirectory();
string[] possibleDirs = {
Path.GetFullPath(Path.Combine(Application.dataPath, "unity-mcp", "Python"))
};
foreach (var dir in possibleDirs)
{
if (Directory.Exists(dir) && File.Exists(Path.Combine(dir, "server.py")))
{
pythonDir = dir;
break;
}
}
// If we couldn't find a Python directory, try to get the Assets path as a fallback
if (string.IsNullOrEmpty(pythonDir))
{
pythonDir = "/path/to/your/unity-mcp/Python";
}
// Create the manual configuration message // Create the manual configuration message
var jsonConfig = new MCPConfig var jsonConfig = new MCPConfig
@ -466,6 +448,68 @@ public class MCPEditorWindow : EditorWindow
// Show a dedicated configuration window instead of console logs // Show a dedicated configuration window instead of console logs
ManualConfigWindow.ShowWindow(configPath, manualConfigJson); ManualConfigWindow.ShowWindow(configPath, manualConfigJson);
} }
private string FindPackagePythonDirectory()
{
string pythonDir = "/path/to/your/unity-mcp/Python";
try
{
// Try to find the package using Package Manager API
var request = UnityEditor.PackageManager.Client.List();
while (!request.IsCompleted) { } // Wait for the request to complete
if (request.Status == UnityEditor.PackageManager.StatusCode.Success)
{
foreach (var package in request.Result)
{
UnityEngine.Debug.Log($"Package: {package.name}, Path: {package.resolvedPath}");
if (package.name == "com.justinpbarnett.unity-mcp")
{
string packagePath = package.resolvedPath;
string potentialPythonDir = Path.Combine(packagePath, "Python");
if (Directory.Exists(potentialPythonDir) &&
File.Exists(Path.Combine(potentialPythonDir, "server.py")))
{
UnityEngine.Debug.Log($"Found package Python directory at: {potentialPythonDir}");
return potentialPythonDir;
}
}
}
}
else if (request.Error != null)
{
UnityEngine.Debug.LogError("Failed to list packages: " + request.Error.message);
}
// If not found via Package Manager, try manual approaches
// First check for local installation
string[] possibleDirs = {
Path.GetFullPath(Path.Combine(Application.dataPath, "unity-mcp", "Python"))
};
foreach (var dir in possibleDirs)
{
UnityEngine.Debug.Log($"Checking local directory: {dir}");
if (Directory.Exists(dir) && File.Exists(Path.Combine(dir, "server.py")))
{
UnityEngine.Debug.Log($"Found local Python directory at: {dir}");
return dir;
}
}
// If still not found, return the placeholder path
UnityEngine.Debug.LogWarning("Could not find Python directory, using placeholder path");
}
catch (Exception e)
{
UnityEngine.Debug.LogError($"Error finding package path: {e.Message}");
}
return pythonDir;
}
} }
// Editor window to display manual configuration instructions // Editor window to display manual configuration instructions