2025-05-12 09:25:21 +08:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
2025-08-21 03:59:49 +08:00
|
|
|
using MCPForUnity.Editor.Models;
|
2025-05-12 09:25:21 +08:00
|
|
|
|
2025-08-21 03:59:49 +08:00
|
|
|
namespace MCPForUnity.Editor.Windows
|
2025-05-12 09:25:21 +08:00
|
|
|
{
|
2025-05-12 10:34:04 +08:00
|
|
|
public class VSCodeManualSetupWindow : ManualConfigEditorWindow
|
2025-05-12 09:25:21 +08:00
|
|
|
{
|
2025-07-30 04:01:17 +08:00
|
|
|
public static void ShowWindow(string configPath, string configJson)
|
2025-05-12 09:25:21 +08:00
|
|
|
{
|
2025-05-12 10:34:04 +08:00
|
|
|
var window = GetWindow<VSCodeManualSetupWindow>("VSCode GitHub Copilot Setup");
|
2025-05-12 09:25:21 +08:00
|
|
|
window.configPath = configPath;
|
|
|
|
|
window.configJson = configJson;
|
|
|
|
|
window.minSize = new Vector2(550, 500);
|
2025-05-12 10:34:04 +08:00
|
|
|
|
|
|
|
|
// Create a McpClient for VSCode
|
|
|
|
|
window.mcpClient = new McpClient
|
|
|
|
|
{
|
|
|
|
|
name = "VSCode GitHub Copilot",
|
|
|
|
|
mcpType = McpTypes.VSCode
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-12 09:25:21 +08:00
|
|
|
window.Show();
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-12 10:34:04 +08:00
|
|
|
protected override void OnGUI()
|
2025-05-12 09:25:21 +08:00
|
|
|
{
|
|
|
|
|
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
|
|
|
|
|
|
|
|
|
|
// Header with improved styling
|
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
|
Rect titleRect = EditorGUILayout.GetControlRect(false, 30);
|
|
|
|
|
EditorGUI.DrawRect(
|
|
|
|
|
new Rect(titleRect.x, titleRect.y, titleRect.width, titleRect.height),
|
|
|
|
|
new Color(0.2f, 0.2f, 0.2f, 0.1f)
|
|
|
|
|
);
|
|
|
|
|
GUI.Label(
|
|
|
|
|
new Rect(titleRect.x + 10, titleRect.y + 6, titleRect.width - 20, titleRect.height),
|
|
|
|
|
"VSCode GitHub Copilot MCP Setup",
|
|
|
|
|
EditorStyles.boldLabel
|
|
|
|
|
);
|
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
|
|
|
|
|
|
// Instructions with improved styling
|
|
|
|
|
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
|
|
|
|
|
|
|
|
|
|
Rect headerRect = EditorGUILayout.GetControlRect(false, 24);
|
|
|
|
|
EditorGUI.DrawRect(
|
|
|
|
|
new Rect(headerRect.x, headerRect.y, headerRect.width, headerRect.height),
|
|
|
|
|
new Color(0.1f, 0.1f, 0.1f, 0.2f)
|
|
|
|
|
);
|
|
|
|
|
GUI.Label(
|
|
|
|
|
new Rect(
|
|
|
|
|
headerRect.x + 8,
|
|
|
|
|
headerRect.y + 4,
|
|
|
|
|
headerRect.width - 16,
|
|
|
|
|
headerRect.height
|
|
|
|
|
),
|
2025-08-21 03:59:49 +08:00
|
|
|
"Setting up GitHub Copilot in VSCode with MCP for Unity",
|
2025-05-12 09:25:21 +08:00
|
|
|
EditorStyles.boldLabel
|
|
|
|
|
);
|
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
|
|
|
|
|
|
GUIStyle instructionStyle = new(EditorStyles.wordWrappedLabel)
|
|
|
|
|
{
|
|
|
|
|
margin = new RectOffset(10, 10, 5, 5),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.LabelField(
|
|
|
|
|
"1. Prerequisites",
|
|
|
|
|
EditorStyles.boldLabel
|
|
|
|
|
);
|
|
|
|
|
EditorGUILayout.LabelField(
|
|
|
|
|
"• Ensure you have VSCode installed",
|
|
|
|
|
instructionStyle
|
|
|
|
|
);
|
|
|
|
|
EditorGUILayout.LabelField(
|
|
|
|
|
"• Ensure you have GitHub Copilot extension installed in VSCode",
|
|
|
|
|
instructionStyle
|
|
|
|
|
);
|
|
|
|
|
EditorGUILayout.LabelField(
|
|
|
|
|
"• Ensure you have a valid GitHub Copilot subscription",
|
|
|
|
|
instructionStyle
|
|
|
|
|
);
|
|
|
|
|
EditorGUILayout.Space(5);
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.LabelField(
|
|
|
|
|
"2. Steps to Configure",
|
|
|
|
|
EditorStyles.boldLabel
|
|
|
|
|
);
|
|
|
|
|
EditorGUILayout.LabelField(
|
|
|
|
|
"a) Open VSCode Settings (File > Preferences > Settings)",
|
|
|
|
|
instructionStyle
|
|
|
|
|
);
|
|
|
|
|
EditorGUILayout.LabelField(
|
|
|
|
|
"b) Click on the 'Open Settings (JSON)' button in the top right",
|
|
|
|
|
instructionStyle
|
|
|
|
|
);
|
|
|
|
|
EditorGUILayout.LabelField(
|
|
|
|
|
"c) Add the MCP configuration shown below to your settings.json file",
|
|
|
|
|
instructionStyle
|
|
|
|
|
);
|
|
|
|
|
EditorGUILayout.LabelField(
|
|
|
|
|
"d) Save the file and restart VSCode",
|
|
|
|
|
instructionStyle
|
|
|
|
|
);
|
|
|
|
|
EditorGUILayout.Space(5);
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.LabelField(
|
|
|
|
|
"3. VSCode settings.json location:",
|
|
|
|
|
EditorStyles.boldLabel
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Path section with improved styling
|
|
|
|
|
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
|
|
|
|
|
string displayPath;
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
{
|
|
|
|
|
displayPath = System.IO.Path.Combine(
|
|
|
|
|
System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData),
|
|
|
|
|
"Code",
|
|
|
|
|
"User",
|
|
|
|
|
"settings.json"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
displayPath = System.IO.Path.Combine(
|
|
|
|
|
System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile),
|
|
|
|
|
"Library",
|
|
|
|
|
"Application Support",
|
|
|
|
|
"Code",
|
|
|
|
|
"User",
|
|
|
|
|
"settings.json"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-12 10:34:04 +08:00
|
|
|
// Store the path in the base class config path
|
|
|
|
|
if (string.IsNullOrEmpty(configPath))
|
|
|
|
|
{
|
|
|
|
|
configPath = displayPath;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-12 09:25:21 +08:00
|
|
|
// Prevent text overflow by allowing the text field to wrap
|
|
|
|
|
GUIStyle pathStyle = new(EditorStyles.textField) { wordWrap = true };
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.TextField(
|
|
|
|
|
displayPath,
|
|
|
|
|
pathStyle,
|
|
|
|
|
GUILayout.Height(EditorGUIUtility.singleLineHeight)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Copy button with improved styling
|
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
|
|
|
GUILayout.FlexibleSpace();
|
|
|
|
|
GUIStyle copyButtonStyle = new(GUI.skin.button)
|
|
|
|
|
{
|
|
|
|
|
padding = new RectOffset(15, 15, 5, 5),
|
|
|
|
|
margin = new RectOffset(10, 10, 5, 5),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
GUILayout.Button(
|
|
|
|
|
"Copy Path",
|
|
|
|
|
copyButtonStyle,
|
|
|
|
|
GUILayout.Height(25),
|
|
|
|
|
GUILayout.Width(100)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
EditorGUIUtility.systemCopyBuffer = displayPath;
|
|
|
|
|
pathCopied = true;
|
|
|
|
|
copyFeedbackTimer = 2f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
GUILayout.Button(
|
|
|
|
|
"Open File",
|
|
|
|
|
copyButtonStyle,
|
|
|
|
|
GUILayout.Height(25),
|
|
|
|
|
GUILayout.Width(100)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
// Open the file using the system's default application
|
|
|
|
|
System.Diagnostics.Process.Start(
|
|
|
|
|
new System.Diagnostics.ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = displayPath,
|
|
|
|
|
UseShellExecute = true,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pathCopied)
|
|
|
|
|
{
|
|
|
|
|
GUIStyle feedbackStyle = new(EditorStyles.label);
|
|
|
|
|
feedbackStyle.normal.textColor = Color.green;
|
|
|
|
|
EditorGUILayout.LabelField("Copied!", feedbackStyle, GUILayout.Width(60));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
|
EditorGUILayout.EndVertical();
|
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.LabelField(
|
|
|
|
|
"4. Add this configuration to your settings.json:",
|
|
|
|
|
EditorStyles.boldLabel
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// JSON section with improved styling
|
|
|
|
|
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
|
|
|
|
|
|
|
|
|
|
// Improved text area for JSON with syntax highlighting colors
|
|
|
|
|
GUIStyle jsonStyle = new(EditorStyles.textArea)
|
|
|
|
|
{
|
|
|
|
|
font = EditorStyles.boldFont,
|
|
|
|
|
wordWrap = true,
|
|
|
|
|
};
|
|
|
|
|
jsonStyle.normal.textColor = new Color(0.3f, 0.6f, 0.9f); // Syntax highlighting blue
|
|
|
|
|
|
|
|
|
|
// Draw the JSON in a text area with a taller height for better readability
|
|
|
|
|
EditorGUILayout.TextArea(configJson, jsonStyle, GUILayout.Height(200));
|
|
|
|
|
|
|
|
|
|
// Copy JSON button with improved styling
|
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
|
|
|
GUILayout.FlexibleSpace();
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
GUILayout.Button(
|
|
|
|
|
"Copy JSON",
|
|
|
|
|
copyButtonStyle,
|
|
|
|
|
GUILayout.Height(25),
|
|
|
|
|
GUILayout.Width(100)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
EditorGUIUtility.systemCopyBuffer = configJson;
|
|
|
|
|
jsonCopied = true;
|
|
|
|
|
copyFeedbackTimer = 2f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (jsonCopied)
|
|
|
|
|
{
|
|
|
|
|
GUIStyle feedbackStyle = new(EditorStyles.label);
|
|
|
|
|
feedbackStyle.normal.textColor = Color.green;
|
|
|
|
|
EditorGUILayout.LabelField("Copied!", feedbackStyle, GUILayout.Width(60));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
|
EditorGUILayout.EndVertical();
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
|
EditorGUILayout.LabelField(
|
|
|
|
|
"5. After configuration:",
|
|
|
|
|
EditorStyles.boldLabel
|
|
|
|
|
);
|
|
|
|
|
EditorGUILayout.LabelField(
|
|
|
|
|
"• Restart VSCode",
|
|
|
|
|
instructionStyle
|
|
|
|
|
);
|
|
|
|
|
EditorGUILayout.LabelField(
|
|
|
|
|
"• GitHub Copilot will now be able to interact with your Unity project through the MCP protocol",
|
|
|
|
|
instructionStyle
|
|
|
|
|
);
|
|
|
|
|
EditorGUILayout.LabelField(
|
2025-08-21 03:59:49 +08:00
|
|
|
"• Remember to have the MCP for Unity Bridge running in Unity Editor",
|
2025-05-12 09:25:21 +08:00
|
|
|
instructionStyle
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.EndVertical();
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
|
|
|
|
|
|
// Close button at the bottom
|
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
|
|
|
GUILayout.FlexibleSpace();
|
|
|
|
|
if (GUILayout.Button("Close", GUILayout.Height(30), GUILayout.Width(100)))
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
GUILayout.FlexibleSpace();
|
|
|
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.EndScrollView();
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-12 10:34:04 +08:00
|
|
|
protected override void Update()
|
2025-05-12 09:25:21 +08:00
|
|
|
{
|
2025-05-12 10:34:04 +08:00
|
|
|
// Call the base implementation which handles the copy feedback timer
|
|
|
|
|
base.Update();
|
2025-05-12 09:25:21 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|