mcpforunityserver 9.2.0__tar.gz → 9.3.0b20260128055651__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mcpforunityserver-9.2.0/src/mcpforunityserver.egg-info → mcpforunityserver-9.3.0b20260128055651}/PKG-INFO +1 -1
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/pyproject.toml +1 -1
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/editor.py +27 -1
- mcpforunityserver-9.3.0b20260128055651/src/cli/commands/prefab.py +266 -0
- mcpforunityserver-9.3.0b20260128055651/src/cli/commands/texture.py +538 -0
- mcpforunityserver-9.3.0b20260128055651/src/cli/commands/tool.py +61 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/vfx.py +51 -15
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/main.py +33 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/utils/connection.py +37 -0
- mcpforunityserver-9.3.0b20260128055651/src/cli/utils/suggestions.py +34 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/main.py +125 -6
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651/src/mcpforunityserver.egg-info}/PKG-INFO +1 -1
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/mcpforunityserver.egg-info/SOURCES.txt +5 -0
- mcpforunityserver-9.3.0b20260128055651/src/services/resources/prefab.py +191 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/manage_components.py +1 -1
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/manage_gameobject.py +43 -23
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/manage_material.py +2 -2
- mcpforunityserver-9.3.0b20260128055651/src/services/tools/manage_prefabs.py +165 -0
- mcpforunityserver-9.3.0b20260128055651/src/services/tools/manage_texture.py +667 -0
- mcpforunityserver-9.3.0b20260128055651/src/services/tools/manage_vfx.py +120 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/tests/test_cli.py +119 -0
- mcpforunityserver-9.2.0/src/cli/commands/prefab.py +0 -144
- mcpforunityserver-9.2.0/src/services/tools/manage_prefabs.py +0 -68
- mcpforunityserver-9.2.0/src/services/tools/manage_vfx.py +0 -738
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/LICENSE +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/README.md +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/setup.cfg +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/__init__.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/__init__.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/animation.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/asset.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/audio.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/batch.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/code.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/component.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/gameobject.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/instance.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/lighting.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/material.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/scene.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/script.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/shader.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/ui.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/utils/__init__.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/utils/config.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/utils/output.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/core/__init__.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/core/config.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/core/logging_decorator.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/core/telemetry.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/core/telemetry_decorator.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/mcpforunityserver.egg-info/dependency_links.txt +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/mcpforunityserver.egg-info/entry_points.txt +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/mcpforunityserver.egg-info/requires.txt +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/mcpforunityserver.egg-info/top_level.txt +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/models/__init__.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/models/models.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/models/unity_response.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/__init__.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/custom_tool_service.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/registry/__init__.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/registry/resource_registry.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/registry/tool_registry.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/resources/__init__.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/resources/active_tool.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/resources/custom_tools.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/resources/editor_state.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/resources/gameobject.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/resources/layers.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/resources/menu_items.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/resources/prefab_stage.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/resources/project_info.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/resources/selection.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/resources/tags.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/resources/tests.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/resources/unity_instances.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/resources/windows.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/state/external_changes_scanner.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/__init__.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/batch_execute.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/debug_request_context.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/execute_custom_tool.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/execute_menu_item.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/find_gameobjects.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/find_in_file.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/manage_asset.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/manage_editor.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/manage_scene.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/manage_script.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/manage_scriptable_object.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/manage_shader.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/preflight.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/read_console.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/refresh_unity.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/run_tests.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/script_apply_edits.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/set_active_instance.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/services/tools/utils.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/transport/__init__.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/transport/legacy/port_discovery.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/transport/legacy/stdio_port_registry.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/transport/legacy/unity_connection.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/transport/models.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/transport/plugin_hub.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/transport/plugin_registry.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/transport/unity_instance_middleware.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/transport/unity_transport.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/utils/focus_nudge.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/utils/module_discovery.py +0 -0
- {mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/utils/reload_sentinel.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mcpforunityserver
|
|
3
|
-
Version: 9.
|
|
3
|
+
Version: 9.3.0b20260128055651
|
|
4
4
|
Summary: MCP for Unity Server: A Unity package for Unity Editor integration via the Model Context Protocol (MCP).
|
|
5
5
|
Author-email: Marcus Sanatan <msanatan@gmail.com>, David Sarno <david.sarno@gmail.com>, Wu Shutong <martinwfire@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
{mcpforunityserver-9.2.0 → mcpforunityserver-9.3.0b20260128055651}/src/cli/commands/editor.py
RENAMED
|
@@ -6,7 +6,8 @@ from typing import Optional, Any
|
|
|
6
6
|
|
|
7
7
|
from cli.utils.config import get_config
|
|
8
8
|
from cli.utils.output import format_output, print_error, print_success, print_info
|
|
9
|
-
from cli.utils.connection import run_command, UnityConnectionError
|
|
9
|
+
from cli.utils.connection import run_command, run_list_custom_tools, UnityConnectionError
|
|
10
|
+
from cli.utils.suggestions import suggest_matches, format_suggestions
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
@click.group()
|
|
@@ -472,6 +473,9 @@ def custom_tool(tool_name: str, params: str):
|
|
|
472
473
|
params_dict = json.loads(params)
|
|
473
474
|
except json.JSONDecodeError as e:
|
|
474
475
|
print_error(f"Invalid JSON for params: {e}")
|
|
476
|
+
print_info("Example: --params '{\"key\":\"value\"}'")
|
|
477
|
+
print_info(
|
|
478
|
+
"Tip: wrap JSON in single quotes to avoid shell escaping issues.")
|
|
475
479
|
sys.exit(1)
|
|
476
480
|
|
|
477
481
|
try:
|
|
@@ -482,6 +486,28 @@ def custom_tool(tool_name: str, params: str):
|
|
|
482
486
|
click.echo(format_output(result, config.format))
|
|
483
487
|
if result.get("success"):
|
|
484
488
|
print_success(f"Executed custom tool: {tool_name}")
|
|
489
|
+
else:
|
|
490
|
+
message = (result.get("message")
|
|
491
|
+
or result.get("error") or "").lower()
|
|
492
|
+
if "not found" in message and "tool" in message:
|
|
493
|
+
try:
|
|
494
|
+
tools_result = run_list_custom_tools(config)
|
|
495
|
+
tools = tools_result.get("tools")
|
|
496
|
+
if tools is None:
|
|
497
|
+
data = tools_result.get("data", {})
|
|
498
|
+
tools = data.get("tools") if isinstance(
|
|
499
|
+
data, dict) else None
|
|
500
|
+
names = [
|
|
501
|
+
t.get("name") for t in tools if isinstance(t, dict) and t.get("name")
|
|
502
|
+
] if isinstance(tools, list) else []
|
|
503
|
+
matches = suggest_matches(tool_name, names)
|
|
504
|
+
suggestion = format_suggestions(matches)
|
|
505
|
+
if suggestion:
|
|
506
|
+
print_info(suggestion)
|
|
507
|
+
print_info(
|
|
508
|
+
f'Example: unity-mcp editor custom-tool "{matches[0]}"')
|
|
509
|
+
except UnityConnectionError:
|
|
510
|
+
pass
|
|
485
511
|
except UnityConnectionError as e:
|
|
486
512
|
print_error(str(e))
|
|
487
513
|
sys.exit(1)
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"""Prefab CLI commands."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import click
|
|
5
|
+
from typing import Optional, Any
|
|
6
|
+
|
|
7
|
+
from cli.utils.config import get_config
|
|
8
|
+
from cli.utils.output import format_output, print_error, print_success
|
|
9
|
+
from cli.utils.connection import run_command, UnityConnectionError
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@click.group()
|
|
13
|
+
def prefab():
|
|
14
|
+
"""Prefab operations - info, hierarchy, open, save, close, create prefabs."""
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@prefab.command("open")
|
|
19
|
+
@click.argument("path")
|
|
20
|
+
def open_stage(path: str):
|
|
21
|
+
"""Open a prefab in the prefab stage for editing.
|
|
22
|
+
|
|
23
|
+
\b
|
|
24
|
+
Examples:
|
|
25
|
+
unity-mcp prefab open "Assets/Prefabs/Player.prefab"
|
|
26
|
+
"""
|
|
27
|
+
config = get_config()
|
|
28
|
+
|
|
29
|
+
params: dict[str, Any] = {
|
|
30
|
+
"action": "open_stage",
|
|
31
|
+
"prefabPath": path,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
result = run_command("manage_prefabs", params, config)
|
|
36
|
+
click.echo(format_output(result, config.format))
|
|
37
|
+
if result.get("success"):
|
|
38
|
+
print_success(f"Opened prefab: {path}")
|
|
39
|
+
except UnityConnectionError as e:
|
|
40
|
+
print_error(str(e))
|
|
41
|
+
sys.exit(1)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@prefab.command("close")
|
|
45
|
+
@click.option(
|
|
46
|
+
"--save", "-s",
|
|
47
|
+
is_flag=True,
|
|
48
|
+
help="Save the prefab before closing."
|
|
49
|
+
)
|
|
50
|
+
def close_stage(save: bool):
|
|
51
|
+
"""Close the current prefab stage.
|
|
52
|
+
|
|
53
|
+
\b
|
|
54
|
+
Examples:
|
|
55
|
+
unity-mcp prefab close
|
|
56
|
+
unity-mcp prefab close --save
|
|
57
|
+
"""
|
|
58
|
+
config = get_config()
|
|
59
|
+
|
|
60
|
+
params: dict[str, Any] = {
|
|
61
|
+
"action": "close_stage",
|
|
62
|
+
}
|
|
63
|
+
if save:
|
|
64
|
+
params["saveBeforeClose"] = True
|
|
65
|
+
|
|
66
|
+
try:
|
|
67
|
+
result = run_command("manage_prefabs", params, config)
|
|
68
|
+
click.echo(format_output(result, config.format))
|
|
69
|
+
if result.get("success"):
|
|
70
|
+
print_success("Closed prefab stage")
|
|
71
|
+
except UnityConnectionError as e:
|
|
72
|
+
print_error(str(e))
|
|
73
|
+
sys.exit(1)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@prefab.command("save")
|
|
77
|
+
@click.option(
|
|
78
|
+
"--force", "-f",
|
|
79
|
+
is_flag=True,
|
|
80
|
+
help="Force save even if no changes detected. Useful for automated workflows."
|
|
81
|
+
)
|
|
82
|
+
def save_stage(force: bool):
|
|
83
|
+
"""Save the currently open prefab stage.
|
|
84
|
+
|
|
85
|
+
\b
|
|
86
|
+
Examples:
|
|
87
|
+
unity-mcp prefab save
|
|
88
|
+
unity-mcp prefab save --force
|
|
89
|
+
"""
|
|
90
|
+
config = get_config()
|
|
91
|
+
|
|
92
|
+
params: dict[str, Any] = {
|
|
93
|
+
"action": "save_open_stage",
|
|
94
|
+
}
|
|
95
|
+
if force:
|
|
96
|
+
params["force"] = True
|
|
97
|
+
|
|
98
|
+
try:
|
|
99
|
+
result = run_command("manage_prefabs", params, config)
|
|
100
|
+
click.echo(format_output(result, config.format))
|
|
101
|
+
if result.get("success"):
|
|
102
|
+
print_success("Saved prefab")
|
|
103
|
+
except UnityConnectionError as e:
|
|
104
|
+
print_error(str(e))
|
|
105
|
+
sys.exit(1)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@prefab.command("info")
|
|
109
|
+
@click.argument("path")
|
|
110
|
+
@click.option(
|
|
111
|
+
"--compact", "-c",
|
|
112
|
+
is_flag=True,
|
|
113
|
+
help="Show compact output (key values only)."
|
|
114
|
+
)
|
|
115
|
+
def info(path: str, compact: bool):
|
|
116
|
+
"""Get information about a prefab asset.
|
|
117
|
+
|
|
118
|
+
\b
|
|
119
|
+
Examples:
|
|
120
|
+
unity-mcp prefab info "Assets/Prefabs/Player.prefab"
|
|
121
|
+
unity-mcp prefab info "Assets/Prefabs/UI.prefab" --compact
|
|
122
|
+
"""
|
|
123
|
+
config = get_config()
|
|
124
|
+
|
|
125
|
+
params: dict[str, Any] = {
|
|
126
|
+
"action": "get_info",
|
|
127
|
+
"prefabPath": path,
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
try:
|
|
131
|
+
result = run_command("manage_prefabs", params, config)
|
|
132
|
+
# Get the actual response data from the wrapped result structure
|
|
133
|
+
response_data = result.get("result", result)
|
|
134
|
+
if compact and response_data.get("success") and response_data.get("data"):
|
|
135
|
+
data = response_data["data"]
|
|
136
|
+
click.echo(f"Prefab: {data.get('assetPath', path)}")
|
|
137
|
+
click.echo(f" Type: {data.get('prefabType', 'Unknown')}")
|
|
138
|
+
click.echo(f" Root: {data.get('rootObjectName', 'N/A')}")
|
|
139
|
+
click.echo(f" GUID: {data.get('guid', 'N/A')}")
|
|
140
|
+
click.echo(
|
|
141
|
+
f" Components: {len(data.get('rootComponentTypes', []))}")
|
|
142
|
+
click.echo(f" Children: {data.get('childCount', 0)}")
|
|
143
|
+
if data.get('isVariant'):
|
|
144
|
+
click.echo(f" Variant of: {data.get('parentPrefab', 'N/A')}")
|
|
145
|
+
else:
|
|
146
|
+
click.echo(format_output(result, config.format))
|
|
147
|
+
except UnityConnectionError as e:
|
|
148
|
+
print_error(str(e))
|
|
149
|
+
sys.exit(1)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@prefab.command("hierarchy")
|
|
153
|
+
@click.argument("path")
|
|
154
|
+
@click.option(
|
|
155
|
+
"--compact", "-c",
|
|
156
|
+
is_flag=True,
|
|
157
|
+
help="Show compact output (names and paths only)."
|
|
158
|
+
)
|
|
159
|
+
@click.option(
|
|
160
|
+
"--show-prefab-info", "-p",
|
|
161
|
+
is_flag=True,
|
|
162
|
+
help="Show prefab nesting information."
|
|
163
|
+
)
|
|
164
|
+
def hierarchy(path: str, compact: bool, show_prefab_info: bool):
|
|
165
|
+
"""Get the hierarchical structure of a prefab.
|
|
166
|
+
|
|
167
|
+
\b
|
|
168
|
+
Examples:
|
|
169
|
+
unity-mcp prefab hierarchy "Assets/Prefabs/Player.prefab"
|
|
170
|
+
unity-mcp prefab hierarchy "Assets/Prefabs/UI.prefab" --compact
|
|
171
|
+
unity-mcp prefab hierarchy "Assets/Prefabs/Complex.prefab" --show-prefab-info
|
|
172
|
+
"""
|
|
173
|
+
config = get_config()
|
|
174
|
+
|
|
175
|
+
params: dict[str, Any] = {
|
|
176
|
+
"action": "get_hierarchy",
|
|
177
|
+
"prefabPath": path,
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
try:
|
|
181
|
+
result = run_command("manage_prefabs", params, config)
|
|
182
|
+
# Get the actual response data from the wrapped result structure
|
|
183
|
+
response_data = result.get("result", result)
|
|
184
|
+
if compact and response_data.get("success") and response_data.get("data"):
|
|
185
|
+
data = response_data["data"]
|
|
186
|
+
items = data.get("items", [])
|
|
187
|
+
for item in items:
|
|
188
|
+
indent = " " * item.get("path", "").count("/")
|
|
189
|
+
prefab_info = ""
|
|
190
|
+
if show_prefab_info and item.get("prefab", {}).get("isNestedRoot"):
|
|
191
|
+
prefab_info = f" [nested: {item['prefab']['assetPath']}]"
|
|
192
|
+
click.echo(f"{indent}{item.get('name')}{prefab_info}")
|
|
193
|
+
click.echo(f"\nTotal: {data.get('total', 0)} objects")
|
|
194
|
+
elif show_prefab_info:
|
|
195
|
+
# Show prefab info in readable format
|
|
196
|
+
if response_data.get("success") and response_data.get("data"):
|
|
197
|
+
data = response_data["data"]
|
|
198
|
+
items = data.get("items", [])
|
|
199
|
+
for item in items:
|
|
200
|
+
prefab = item.get("prefab", {})
|
|
201
|
+
prefab_info = ""
|
|
202
|
+
if prefab.get("isRoot"):
|
|
203
|
+
prefab_info = " [root]"
|
|
204
|
+
elif prefab.get("isNestedRoot"):
|
|
205
|
+
prefab_info = f" [nested: {prefab.get('nestingDepth', 0)}]"
|
|
206
|
+
click.echo(f"{item.get('path')}{prefab_info}")
|
|
207
|
+
click.echo(f"\nTotal: {data.get('total', 0)} objects")
|
|
208
|
+
else:
|
|
209
|
+
click.echo(format_output(result, config.format))
|
|
210
|
+
else:
|
|
211
|
+
click.echo(format_output(result, config.format))
|
|
212
|
+
except UnityConnectionError as e:
|
|
213
|
+
print_error(str(e))
|
|
214
|
+
sys.exit(1)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
@prefab.command("create")
|
|
218
|
+
@click.argument("target")
|
|
219
|
+
@click.argument("path")
|
|
220
|
+
@click.option(
|
|
221
|
+
"--overwrite",
|
|
222
|
+
is_flag=True,
|
|
223
|
+
help="Overwrite existing prefab at path."
|
|
224
|
+
)
|
|
225
|
+
@click.option(
|
|
226
|
+
"--include-inactive",
|
|
227
|
+
is_flag=True,
|
|
228
|
+
help="Include inactive objects when finding target."
|
|
229
|
+
)
|
|
230
|
+
@click.option(
|
|
231
|
+
"--unlink-if-instance",
|
|
232
|
+
is_flag=True,
|
|
233
|
+
help="Unlink from existing prefab before creating new one."
|
|
234
|
+
)
|
|
235
|
+
def create(target: str, path: str, overwrite: bool, include_inactive: bool, unlink_if_instance: bool):
|
|
236
|
+
"""Create a prefab from a scene GameObject.
|
|
237
|
+
|
|
238
|
+
\b
|
|
239
|
+
Examples:
|
|
240
|
+
unity-mcp prefab create "Player" "Assets/Prefabs/Player.prefab"
|
|
241
|
+
unity-mcp prefab create "Enemy" "Assets/Prefabs/Enemy.prefab" --overwrite
|
|
242
|
+
unity-mcp prefab create "EnemyInstance" "Assets/Prefabs/BossEnemy.prefab" --unlink-if-instance
|
|
243
|
+
"""
|
|
244
|
+
config = get_config()
|
|
245
|
+
|
|
246
|
+
params: dict[str, Any] = {
|
|
247
|
+
"action": "create_from_gameobject",
|
|
248
|
+
"target": target,
|
|
249
|
+
"prefabPath": path,
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if overwrite:
|
|
253
|
+
params["allowOverwrite"] = True
|
|
254
|
+
if include_inactive:
|
|
255
|
+
params["searchInactive"] = True
|
|
256
|
+
if unlink_if_instance:
|
|
257
|
+
params["unlinkIfInstance"] = True
|
|
258
|
+
|
|
259
|
+
try:
|
|
260
|
+
result = run_command("manage_prefabs", params, config)
|
|
261
|
+
click.echo(format_output(result, config.format))
|
|
262
|
+
if result.get("success"):
|
|
263
|
+
print_success(f"Created prefab: {path}")
|
|
264
|
+
except UnityConnectionError as e:
|
|
265
|
+
print_error(str(e))
|
|
266
|
+
sys.exit(1)
|