Skip to content

Commit e70171a

Browse files
committed
bug fixed.
1 parent 453868a commit e70171a

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

UnityMcpBridge/Editor/MCPForUnityBridge.cs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ private static Dictionary<
3737
private static bool isAutoConnectMode = false;
3838
private const ulong MaxFrameBytes = 64UL * 1024 * 1024; // 64 MiB hard cap for framed payloads
3939
private const int FrameIOTimeoutMs = 30000; // Per-read timeout to avoid stalled clients
40-
40+
4141
// Debug helpers
4242
private static bool IsDebugEnabled()
4343
{
4444
try { return EditorPrefs.GetBool("MCPForUnity.DebugLogs", false); } catch { return false; }
4545
}
46-
46+
4747
private static void LogBreadcrumb(string stage)
4848
{
4949
if (IsDebugEnabled())
@@ -62,7 +62,7 @@ private static void LogBreadcrumb(string stage)
6262
public static void StartAutoConnect()
6363
{
6464
Stop(); // Stop current connection
65-
65+
6666
try
6767
{
6868
// Prefer stored project port and start using the robust Start() path (with retries/options)
@@ -251,7 +251,7 @@ public static void Start()
251251
const int maxImmediateRetries = 3;
252252
const int retrySleepMs = 75;
253253
int attempt = 0;
254-
for (;;)
254+
for (; ; )
255255
{
256256
try
257257
{
@@ -578,7 +578,7 @@ private static async System.Threading.Tasks.Task<string> ReadFrameAsUtf8Async(Ne
578578
{
579579
byte[] header = await ReadExactAsync(stream, 8, timeoutMs);
580580
ulong payloadLen = ReadUInt64BigEndian(header);
581-
if (payloadLen > MaxFrameBytes)
581+
if (payloadLen > MaxFrameBytes)
582582
{
583583
throw new System.IO.IOException($"Invalid framed length: {payloadLen}");
584584
}
@@ -795,22 +795,7 @@ private static string ExecuteCommand(Command command)
795795
JObject paramsObject = command.@params ?? new JObject();
796796

797797
// Route command based on the new tool structure from the refactor plan
798-
object result = command.type switch
799-
{
800-
// Maps the command type (tool name) to the corresponding handler's static HandleCommand method
801-
// Assumes each handler class has a static method named 'HandleCommand' that takes JObject parameters
802-
"manage_script" => ManageScript.HandleCommand(paramsObject),
803-
"manage_scene" => ManageScene.HandleCommand(paramsObject),
804-
"manage_editor" => ManageEditor.HandleCommand(paramsObject),
805-
"manage_gameobject" => ManageGameObject.HandleCommand(paramsObject),
806-
"manage_asset" => ManageAsset.HandleCommand(paramsObject),
807-
"manage_shader" => ManageShader.HandleCommand(paramsObject),
808-
"read_console" => ReadConsole.HandleCommand(paramsObject),
809-
"execute_menu_item" => ExecuteMenuItem.HandleCommand(paramsObject),
810-
_ => throw new ArgumentException(
811-
$"Unknown or unsupported command type: {command.type}"
812-
),
813-
};
798+
object result = CommandRegistry.GetHandler(command.type)(paramsObject);
814799

815800
// Standard success response format
816801
var response = new { status = "success", result };

0 commit comments

Comments
 (0)