11using System ;
22using System . Collections . Generic ;
33using System . IO ;
4+ using System . Linq ;
5+ using System . Net ;
6+ using System . Net . NetworkInformation ;
47using System . Net . Sockets ;
58using System . Runtime . InteropServices ;
69using System . Text ;
@@ -18,13 +21,14 @@ public class UnityMcpEditorWindow : EditorWindow
1821 {
1922 private bool isUnityBridgeRunning = false ;
2023 private Vector2 scrollPosition ;
21- private string claudeConfigStatus = "Not configured" ;
22- private string cursorConfigStatus = "Not configured" ;
23- private string pythonServerStatus = "Not Connected" ;
24- private Color pythonServerStatusColor = Color . red ;
24+ private string pythonServerInstallationStatus = "Not Installed" ;
25+ private Color pythonServerInstallationStatusColor = Color . red ;
26+ private string pythonServerConnectionStatus = "Not Connected" ;
27+ private Color pythonServerConnectionStatusColor = Color . red ;
28+ private DateTime lastConnectionCheck ;
2529 private const int unityPort = 6400 ; // Hardcoded Unity port
2630 private const int mcpPort = 6500 ; // Hardcoded MCP port
27- private McpClients mcpClients = new ( ) ;
31+ private readonly McpClients mcpClients = new ( ) ;
2832
2933 [ MenuItem ( "Window/Unity MCP" ) ]
3034 public static void ShowWindow ( )
@@ -34,14 +38,26 @@ public static void ShowWindow()
3438
3539 private void OnEnable ( )
3640 {
37- // Check initial states
41+ UpdatePythonServerInstallationStatus ( ) ;
42+ UpdatePythonServerConnectionStatus ( ) ;
43+
3844 isUnityBridgeRunning = UnityMcpBridge . IsRunning ;
3945 foreach ( McpClient mcpClient in mcpClients . clients )
4046 {
4147 CheckMcpConfiguration ( mcpClient ) ;
4248 }
4349 }
4450
51+ private void Update ( )
52+ {
53+ if ( lastConnectionCheck . AddSeconds ( 2 ) < DateTime . Now )
54+ {
55+ UpdatePythonServerConnectionStatus ( ) ;
56+
57+ lastConnectionCheck = DateTime . Now ;
58+ }
59+ }
60+
4561 private Color GetStatusColor ( McpStatus status )
4662 {
4763 // Return appropriate color based on the status enum
@@ -57,6 +73,62 @@ private Color GetStatusColor(McpStatus status)
5773 } ;
5874 }
5975
76+ private void UpdatePythonServerInstallationStatus ( )
77+ {
78+ string serverPath = ServerInstaller . GetServerPath ( ) ;
79+
80+ if ( File . Exists ( Path . Combine ( serverPath , "server.py" ) ) )
81+ {
82+ string installedVersion = ServerInstaller . GetInstalledVersion ( ) ;
83+ string latestVersion = ServerInstaller . GetLatestVersion ( ) ;
84+
85+ if ( ServerInstaller . IsNewerVersion ( latestVersion , installedVersion ) )
86+ {
87+ pythonServerInstallationStatus = "Up to Date" ;
88+ pythonServerInstallationStatusColor = Color . green ;
89+ }
90+ else
91+ {
92+ pythonServerInstallationStatus = "Newer Version Available" ;
93+ pythonServerInstallationStatusColor = Color . yellow ;
94+ }
95+ }
96+ else
97+ {
98+ pythonServerInstallationStatus = "Not Installed" ;
99+ pythonServerInstallationStatusColor = Color . red ;
100+ }
101+ }
102+
103+ private void UpdatePythonServerConnectionStatus ( )
104+ {
105+ IPGlobalProperties ipGlobalProperties = IPGlobalProperties . GetIPGlobalProperties ( ) ;
106+ TcpConnectionInformation [ ] tcpConnections =
107+ ipGlobalProperties . GetActiveTcpConnections ( ) ;
108+ IPEndPoint [ ] tcpListeners = ipGlobalProperties . GetActiveTcpListeners ( ) ;
109+
110+ // Check if the port is in use by any active listener
111+ bool isListenerActive = tcpListeners . Any ( static endpoint => endpoint . Port == mcpPort ) ;
112+
113+ // Optionally, check if the port is in use by any active connection
114+ bool isConnectionActive = tcpConnections . Any ( static connection =>
115+ connection . LocalEndPoint . Port == mcpPort
116+ || connection . RemoteEndPoint . Port == mcpPort
117+ ) ;
118+
119+ // Return true if either a listener or connection is using the port
120+ if ( isListenerActive || isConnectionActive )
121+ {
122+ pythonServerConnectionStatus = "Connected" ;
123+ pythonServerConnectionStatusColor = Color . green ;
124+ }
125+ else
126+ {
127+ pythonServerConnectionStatus = "Not Connected" ;
128+ pythonServerConnectionStatusColor = Color . red ;
129+ }
130+ }
131+
60132 private void ConfigurationSection ( McpClient mcpClient )
61133 {
62134 // Calculate if we should use half-width layout
@@ -197,8 +269,8 @@ private void OnGUI()
197269
198270 // Status indicator with colored dot
199271 var statusRect = EditorGUILayout . BeginHorizontal ( GUILayout . Height ( 20 ) ) ;
200- DrawStatusDot ( statusRect , pythonServerStatusColor ) ;
201- EditorGUILayout . LabelField ( " " + pythonServerStatus ) ;
272+ DrawStatusDot ( statusRect , pythonServerInstallationStatusColor ) ;
273+ EditorGUILayout . LabelField ( " " + pythonServerInstallationStatus ) ;
202274 EditorGUILayout . EndHorizontal ( ) ;
203275
204276 EditorGUILayout . LabelField ( $ "Unity Port: { unityPort } ") ;
0 commit comments