Skip to content

Commit 67b48ff

Browse files
committed
Updates of fixes for ui and material
1 parent 9a68f0e commit 67b48ff

8 files changed

Lines changed: 34 additions & 11 deletions

File tree

.claude/skills/unity-mcp-skill/references/tools-reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ manage_ui(
669669
3. Create an empty GameObject and attach UIDocument with the UXML source
670670
4. Use `get_visual_tree` to inspect the result
671671

672+
**Important:** Always use `<ui:Style>` (with the `ui:` namespace prefix) in UXML files, not bare `<Style>`. UI Builder will fail to open files that use `<Style>` without the prefix.
673+
672674
---
673675

674676
## Editor Control Tools

.claude/skills/unity-mcp-skill/references/workflows.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,8 @@ Unity has two UI systems: **UI Toolkit** (modern, recommended) and **uGUI** (Can
607607

608608
UI Toolkit uses a web-like approach: **UXML** (like HTML) for structure, **USS** (like CSS) for styling. This is the preferred UI system for new projects.
609609

610+
> **Important:** Always use `<ui:Style>` (with the `ui:` namespace prefix) in UXML, not bare `<Style>`. UI Builder will fail to open files that use `<Style>` without the prefix.
611+
610612
#### Create a Complete UI Screen
611613

612614
```python

MCPForUnity/Editor/Tools/ManageMaterial.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ private static object SetRendererColor(JObject @params)
258258
}
259259

260260
int slot = p.GetInt("slot") ?? 0;
261-
string mode = p.Get("mode", "property_block");
261+
string mode = p.Get("mode", "create_unique");
262262

263263
Color color;
264264
try
@@ -390,17 +390,30 @@ private static void SetColorProperties(Material mat, Color color)
390390
private static object CreateUniqueAndAssign(Renderer renderer, GameObject go, Color color, int slot)
391391
{
392392
string safeName = go.name.Replace(" ", "_");
393-
string matPath = $"Assets/Materials/{safeName}_{go.GetInstanceID()}_mat.mat";
393+
394+
// Derive material folder from the scene context so generated materials
395+
// live next to the scene/generation folder instead of a global dump.
396+
string materialFolder = "Assets/Materials";
397+
var scene = go.scene;
398+
if (scene.IsValid() && !string.IsNullOrEmpty(scene.path))
399+
{
400+
string sceneDir = System.IO.Path.GetDirectoryName(scene.path).Replace("\\", "/");
401+
materialFolder = $"{sceneDir}/Materials";
402+
}
403+
404+
string matPath = $"{materialFolder}/{safeName}_{go.GetInstanceID()}_mat.mat";
394405
matPath = AssetPathUtility.SanitizeAssetPath(matPath);
395406
if (matPath == null)
396407
{
397408
return new ErrorResponse($"Invalid GameObject name '{go.name}' — cannot build a safe material path.");
398409
}
399410

400411
// Ensure the Materials directory exists
401-
if (!AssetDatabase.IsValidFolder("Assets/Materials"))
412+
if (!AssetDatabase.IsValidFolder(materialFolder))
402413
{
403-
AssetDatabase.CreateFolder("Assets", "Materials");
414+
string parentDir = System.IO.Path.GetDirectoryName(materialFolder).Replace("\\", "/");
415+
string folderName = System.IO.Path.GetFileName(materialFolder);
416+
AssetDatabase.CreateFolder(parentDir, folderName);
404417
}
405418

406419
Material existing = AssetDatabase.LoadAssetAtPath<Material>(matPath);

Server/src/cli/commands/material.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def set_property(path: str, property_name: str, value: str):
161161
)
162162
@click.option(
163163
"--mode", "-m",
164-
type=click.Choice(["shared", "instance", "property_block"]),
164+
type=click.Choice(["shared", "instance", "property_block", "create_unique"]),
165165
default="shared",
166166
help="Assignment mode."
167167
)
@@ -208,9 +208,9 @@ def assign(material_path: str, target: str, search_method: Optional[str], slot:
208208
)
209209
@click.option(
210210
"--mode", "-m",
211-
type=click.Choice(["shared", "instance", "property_block"]),
212-
default="property_block",
213-
help="Modification mode."
211+
type=click.Choice(["shared", "instance", "property_block", "create_unique"]),
212+
default="create_unique",
213+
help="Modification mode (default: create_unique — persistent per-object material)."
214214
)
215215
@handle_unity_errors
216216
def set_renderer_color(target: str, r: float, g: float, b: float, a: float, search_method: Optional[str], mode: str):

Server/src/services/tools/manage_material.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ async def manage_material(
5858
search_method: Annotated[Literal["by_id", "by_name", "by_path", "by_tag",
5959
"by_layer", "by_component"], "Search method for target"] | None = None,
6060
slot: Annotated[int, "Material slot index (0-based)"] | None = None,
61-
mode: Annotated[Literal["shared", "instance", "property_block"],
62-
"Assignment/modification mode"] | None = None,
61+
mode: Annotated[Literal["shared", "instance", "property_block", "create_unique"],
62+
"Assignment/modification mode (default: create_unique — creates a persistent per-object material)"] | None = None,
6363

6464
) -> dict[str, Any]:
6565
unity_instance = await get_unity_instance_from_context(ctx)

Server/src/services/tools/manage_ui.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
" call render_ui a second time to retrieve the saved PNG (hasContent will be true).\n"
4343
" - In editor mode: assigns a RenderTexture to PanelSettings (best-effort; may stay blank).\n"
4444
"9. Use detach_ui_document to remove UIDocument from a GameObject\n"
45-
"10. Use delete to remove .uxml/.uss files"
45+
"10. Use delete to remove .uxml/.uss files\n\n"
46+
"Important: Always use <ui:Style> (with the ui: namespace prefix) in UXML, not bare <Style>. "
47+
"UI Builder will fail to open files that use <Style> without the prefix."
4648
),
4749
annotations=ToolAnnotations(
4850
title="Manage UI",

unity-mcp-skill/references/tools-reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,8 @@ manage_ui(
671671
3. Create an empty GameObject and attach UIDocument with the UXML source
672672
4. Use `get_visual_tree` to inspect the result
673673

674+
**Important:** Always use `<ui:Style>` (with the `ui:` namespace prefix) in UXML files, not bare `<Style>`. UI Builder will fail to open files that use `<Style>` without the prefix.
675+
674676
---
675677

676678
## Editor Control Tools

unity-mcp-skill/references/workflows.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ Unity has two UI systems: **UI Toolkit** (modern, recommended) and **uGUI** (Can
610610

611611
UI Toolkit uses a web-like approach: **UXML** (like HTML) for structure, **USS** (like CSS) for styling. This is the preferred UI system for new projects.
612612

613+
> **Important:** Always use `<ui:Style>` (with the `ui:` namespace prefix) in UXML, not bare `<Style>`. UI Builder will fail to open files that use `<Style>` without the prefix.
614+
613615
#### Create a Complete UI Screen
614616

615617
```python

0 commit comments

Comments
 (0)