Skip to content

Commit b85f920

Browse files
authored
Merge pull request #1077 from chenkunqing/codex-fix-mcp-window-open-and-warning
Fix MCP main window reopening logic and remove profiler warning
2 parents c5b6910 + 68cd175 commit b85f920

3 files changed

Lines changed: 42 additions & 16 deletions

File tree

MCPForUnity/Editor/MenuItems/MCPForUnityMenu.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ public static class MCPForUnityMenu
1010
[MenuItem("Window/MCP For Unity/Toggle MCP Window %#m", priority = 1)]
1111
public static void ToggleMCPWindow()
1212
{
13-
if (MCPForUnityEditorWindow.HasAnyOpenWindow())
14-
{
15-
MCPForUnityEditorWindow.CloseAllOpenWindows();
16-
}
17-
else
18-
{
19-
MCPForUnityEditorWindow.ShowWindow();
20-
}
13+
MCPForUnityEditorWindow.ShowWindow();
2114
}
2215

2316
[MenuItem("Window/MCP For Unity/Local Setup Window", priority = 2)]

MCPForUnity/Editor/Tools/Profiler/Operations/SessionOps.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ internal static object Start(JObject @params)
2121

2222
UProfiler.enabled = true;
2323

24-
bool recording = false;
2524
if (!string.IsNullOrEmpty(logFile))
2625
{
2726
string dir = Path.GetDirectoryName(logFile);
@@ -30,7 +29,6 @@ internal static object Start(JObject @params)
3029

3130
UProfiler.logFile = logFile;
3231
UProfiler.enableBinaryLog = true;
33-
recording = true;
3432
}
3533

3634
if (enableCallstacks)

MCPForUnity/Editor/Windows/MCPForUnityEditorWindow.cs

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,45 @@ internal static void CloseAllWindows()
7171
}
7272
}
7373

74-
public static void ShowWindow()
75-
{
76-
var window = GetWindow<MCPForUnityEditorWindow>("MCP For Unity");
77-
window.minSize = new Vector2(500, 340);
78-
}
74+
public static void ShowWindow()
75+
{
76+
var existingWindows = UnityEngine.Resources.FindObjectsOfTypeAll<MCPForUnityEditorWindow>();
77+
MCPForUnityEditorWindow window = null;
78+
79+
if (existingWindows.Length > 0)
80+
{
81+
window = existingWindows[0];
82+
83+
// If multiple instances exist, keep one and close the extras to avoid stale hidden tabs.
84+
for (int i = 1; i < existingWindows.Length; i++)
85+
{
86+
try
87+
{
88+
existingWindows[i].Close();
89+
}
90+
catch (Exception ex)
91+
{
92+
McpLog.Warn($"Error closing duplicate MCP window: {ex.Message}");
93+
}
94+
}
95+
}
96+
else
97+
{
98+
window = GetWindow<MCPForUnityEditorWindow>("MCP For Unity");
99+
}
100+
101+
window.titleContent = new GUIContent("MCP For Unity");
102+
window.minSize = new Vector2(500, 340);
103+
104+
if (window.position.width < 100 || window.position.height < 100)
105+
{
106+
window.position = new Rect(120, 120, 900, 700);
107+
}
108+
109+
window.Show();
110+
window.ShowTab();
111+
window.Focus();
112+
}
79113

80114
// Helper to check and manage open windows from other classes
81115
public static bool HasAnyOpenWindow()
@@ -125,7 +159,8 @@ public void CreateGUI()
125159
return;
126160
}
127161

128-
visualTree.CloneTree(rootVisualElement);
162+
rootVisualElement.Clear();
163+
visualTree.CloneTree(rootVisualElement);
129164

130165
// Load main window USS
131166
var mainStyleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(

0 commit comments

Comments
 (0)