feat: polish game HUD scoring and results

This commit is contained in:
2026-05-29 00:32:21 +09:00
parent c4330aa544
commit b46ccddbdb
14 changed files with 768 additions and 646 deletions
+42 -6
View File
@@ -17,7 +17,8 @@ namespace VRBeats.EditorTools
[InitializeOnLoad]
internal static class UnityCodexBridgeServer
{
private const int Port = 19744;
private const int PreferredPort = 19744;
private const int MaxPortAttempts = 5;
private const string AutoStartPrefKey = "VRBeats.CodexBridge.AutoStart";
private const int MaxLogs = 250;
@@ -28,6 +29,7 @@ namespace VRBeats.EditorTools
private static TcpListener _listener;
private static Thread _serverThread;
private static bool _running;
private static int _port = PreferredPort;
private static int _logIndex;
static UnityCodexBridgeServer()
@@ -103,9 +105,7 @@ namespace VRBeats.EditorTools
try
{
_listener = new TcpListener(IPAddress.Loopback, Port);
_listener.Server.ExclusiveAddressUse = true;
_listener.Start();
_listener = CreateListener();
_running = true;
_serverThread = new Thread(ServerLoop)
@@ -115,7 +115,7 @@ namespace VRBeats.EditorTools
};
_serverThread.Start();
Debug.Log("[CodexBridge] Listening on http://127.0.0.1:" + Port);
Debug.Log("[CodexBridge] Listening on http://127.0.0.1:" + _port);
}
catch (Exception ex)
{
@@ -160,6 +160,42 @@ namespace VRBeats.EditorTools
_serverThread = null;
}
private static TcpListener CreateListener()
{
Exception lastException = null;
for (int i = 0; i < MaxPortAttempts; i++)
{
int port = PreferredPort + i;
TcpListener listener = null;
try
{
listener = new TcpListener(IPAddress.Loopback, port);
listener.Server.ExclusiveAddressUse = true;
listener.Start();
_port = port;
return listener;
}
catch (Exception ex)
{
lastException = ex;
try
{
if (listener != null)
listener.Stop();
}
catch
{
// Ignore cleanup failures while trying fallback ports.
}
}
}
throw lastException ?? new SocketException();
}
private static bool IsBackgroundEditorProcess()
{
string commandLine = Environment.CommandLine;
@@ -391,7 +427,7 @@ namespace VRBeats.EditorTools
string body =
"{\"ok\":true" +
",\"bridge\":\"unity-codex-bridge\"" +
",\"port\":" + Port.ToString(CultureInfo.InvariantCulture) +
",\"port\":" + _port.ToString(CultureInfo.InvariantCulture) +
",\"unityVersion\":" + JsonString(Application.unityVersion) +
",\"projectPath\":" + JsonString(Directory.GetCurrentDirectory()) +
",\"scene\":" + JsonString(scene.IsValid() ? scene.name : string.Empty) +