|
3 | 3 | using MCPForUnity.Editor.Services; |
4 | 4 | using Newtonsoft.Json.Linq; |
5 | 5 | using UnityEditor; |
6 | | -using UnityEditor.SceneManagement; |
7 | 6 | using UnityEditorInternal; // Required for tag management |
8 | 7 | using UnityEngine; |
9 | 8 |
|
@@ -47,8 +46,6 @@ public static object HandleCommand(JObject @params) |
47 | 46 | // Parameters for specific actions |
48 | 47 | string tagName = p.Get("tagName"); |
49 | 48 | string layerName = p.Get("layerName"); |
50 | | - string prefabPath = p.Get("prefabPath") ?? p.Get("path"); |
51 | | - |
52 | 49 | // Route action |
53 | 50 | switch (action) |
54 | 51 | { |
@@ -137,14 +134,6 @@ public static object HandleCommand(JObject @params) |
137 | 134 | // // Handle string name or int index |
138 | 135 | // return SetQualityLevel(@params["qualityLevel"]); |
139 | 136 |
|
140 | | - // Prefab Stage |
141 | | - case "open_prefab_stage": |
142 | | - return OpenPrefabStage(prefabPath); |
143 | | - case "save_prefab_stage": |
144 | | - return SavePrefabStage(); |
145 | | - case "close_prefab_stage": |
146 | | - return ClosePrefabStage(); |
147 | | - |
148 | 137 | // Package Deployment |
149 | 138 | case "deploy_package": |
150 | 139 | return DeployPackage(); |
@@ -182,7 +171,7 @@ public static object HandleCommand(JObject @params) |
182 | 171 |
|
183 | 172 | default: |
184 | 173 | return new ErrorResponse( |
185 | | - $"Unknown action: '{action}'. Supported actions: play, pause, stop, set_active_tool, add_tag, remove_tag, add_layer, remove_layer, open_prefab_stage, save_prefab_stage, close_prefab_stage, deploy_package, restore_package, undo, redo. Use MCP resources for reading editor state, project info, tags, layers, selection, windows, prefab stage, and active tool." |
| 174 | + $"Unknown action: '{action}'. Supported actions: play, pause, stop, set_active_tool, add_tag, remove_tag, add_layer, remove_layer, deploy_package, restore_package, undo, redo. For prefab editing (open/save/close prefab stage), use manage_prefabs. Use MCP resources for reading editor state, project info, tags, layers, selection, windows, prefab stage, and active tool." |
186 | 175 | ); |
187 | 176 | } |
188 | 177 | } |
@@ -402,112 +391,6 @@ private static object RemoveLayer(string layerName) |
402 | 391 | } |
403 | 392 | } |
404 | 393 |
|
405 | | - // --- Prefab Stage Methods --- |
406 | | - |
407 | | - private static object OpenPrefabStage(string requestedPath) |
408 | | - { |
409 | | - if (string.IsNullOrWhiteSpace(requestedPath)) |
410 | | - { |
411 | | - return new ErrorResponse("'prefabPath' parameter is required for open_prefab_stage."); |
412 | | - } |
413 | | - |
414 | | - string sanitizedPath = AssetPathUtility.SanitizeAssetPath(requestedPath); |
415 | | - if (sanitizedPath == null) |
416 | | - { |
417 | | - return new ErrorResponse($"Invalid prefab path (path traversal detected): '{requestedPath}'."); |
418 | | - } |
419 | | - |
420 | | - if (!sanitizedPath.StartsWith("Assets/", StringComparison.OrdinalIgnoreCase)) |
421 | | - { |
422 | | - return new ErrorResponse($"Prefab path must be within the Assets folder. Got: '{sanitizedPath}'."); |
423 | | - } |
424 | | - |
425 | | - if (!sanitizedPath.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase)) |
426 | | - { |
427 | | - return new ErrorResponse($"Prefab path must end with '.prefab'. Got: '{sanitizedPath}'."); |
428 | | - } |
429 | | - |
430 | | - try |
431 | | - { |
432 | | - GameObject prefabAsset = AssetDatabase.LoadAssetAtPath<GameObject>(sanitizedPath); |
433 | | - if (prefabAsset == null) |
434 | | - { |
435 | | - return new ErrorResponse($"Prefab asset not found at '{sanitizedPath}'."); |
436 | | - } |
437 | | - |
438 | | - var prefabStage = PrefabStageUtility.OpenPrefab(sanitizedPath); |
439 | | - bool enteredStage = prefabStage != null |
440 | | - && string.Equals(prefabStage.assetPath, sanitizedPath, StringComparison.OrdinalIgnoreCase) |
441 | | - && prefabStage.prefabContentsRoot != null; |
442 | | - |
443 | | - if (!enteredStage) |
444 | | - { |
445 | | - return new ErrorResponse($"Failed to open prefab stage for '{sanitizedPath}'. PrefabStageUtility.OpenPrefab did not enter the requested prefab stage."); |
446 | | - } |
447 | | - |
448 | | - return new SuccessResponse( |
449 | | - $"Opened prefab stage for '{sanitizedPath}'.", |
450 | | - new |
451 | | - { |
452 | | - prefabPath = sanitizedPath, |
453 | | - openedPrefabPath = prefabStage.assetPath, |
454 | | - rootName = prefabStage.prefabContentsRoot.name, |
455 | | - enteredPrefabStage = enteredStage |
456 | | - } |
457 | | - ); |
458 | | - } |
459 | | - catch (Exception e) |
460 | | - { |
461 | | - return new ErrorResponse($"Error opening prefab stage: {e.Message}"); |
462 | | - } |
463 | | - } |
464 | | - |
465 | | - private static object SavePrefabStage() |
466 | | - { |
467 | | - try |
468 | | - { |
469 | | - var prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); |
470 | | - if (prefabStage == null) |
471 | | - { |
472 | | - return new ErrorResponse("Not currently in prefab editing mode. Open a prefab stage first with open_prefab_stage."); |
473 | | - } |
474 | | - |
475 | | - string prefabPath = prefabStage.assetPath; |
476 | | - EditorSceneManager.MarkSceneDirty(prefabStage.scene); |
477 | | - bool saved = EditorSceneManager.SaveScene(prefabStage.scene); |
478 | | - if (!saved) |
479 | | - { |
480 | | - return new ErrorResponse($"Failed to save prefab stage for '{prefabPath}'. The file may be read-only or the disk may be full."); |
481 | | - } |
482 | | - |
483 | | - return new SuccessResponse($"Saved prefab stage changes for '{prefabPath}'.", new { prefabPath, saved }); |
484 | | - } |
485 | | - catch (Exception e) |
486 | | - { |
487 | | - return new ErrorResponse($"Error saving prefab stage: {e.Message}"); |
488 | | - } |
489 | | - } |
490 | | - |
491 | | - private static object ClosePrefabStage() |
492 | | - { |
493 | | - try |
494 | | - { |
495 | | - var prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); |
496 | | - if (prefabStage == null) |
497 | | - { |
498 | | - return new SuccessResponse("Not currently in prefab editing mode."); |
499 | | - } |
500 | | - |
501 | | - string prefabPath = prefabStage.assetPath; |
502 | | - StageUtility.GoToMainStage(); |
503 | | - return new SuccessResponse($"Exited prefab stage for '{prefabPath}'.", new { prefabPath }); |
504 | | - } |
505 | | - catch (Exception e) |
506 | | - { |
507 | | - return new ErrorResponse($"Error closing prefab stage: {e.Message}"); |
508 | | - } |
509 | | - } |
510 | | - |
511 | 394 | // --- Package Deployment Methods --- |
512 | 395 |
|
513 | 396 | private static object DeployPackage() |
|
0 commit comments