Skip to content

Commit ceef08b

Browse files
committed
Add manage_material tool documentation and fix MaterialOps texture property checks
- Add comprehensive ManageMaterial tool documentation to MCPForUnity/README.md - Add manage_material to tools list in README.md and README-zh.md - Fix MaterialOps.cs to check HasProperty before SetTexture calls to prevent Unity warnings - Ensures consistency with other property setters in MaterialOps
1 parent dc095d5 commit ceef08b

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

MCPForUnity/Editor/Helpers/MaterialOps.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public static bool TrySetShaderProperty(Material material, string propertyName,
303303
// we can try to load it.
304304
var sanitizedPath = AssetPathUtility.SanitizeAssetPath(path);
305305
Texture tex = AssetDatabase.LoadAssetAtPath<Texture>(sanitizedPath);
306-
if (tex != null)
306+
if (tex != null && material.HasProperty(propertyName))
307307
{
308308
material.SetTexture(propertyName, tex);
309309
return true;
@@ -318,7 +318,7 @@ public static bool TrySetShaderProperty(Material material, string propertyName,
318318
try
319319
{
320320
Texture texture = value.ToObject<Texture>(serializer);
321-
if (texture != null)
321+
if (texture != null && material.HasProperty(propertyName))
322322
{
323323
material.SetTexture(propertyName, texture);
324324
return true;

README-zh.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ MCP for Unity 作为桥梁,允许 AI 助手(如 Claude、Cursor)通过本
4444
* `manage_asset`: 执行资源操作(导入、创建、修改、删除等)。
4545
* `manage_editor`: 控制和查询编辑器的状态和设置。
4646
* `manage_gameobject`: 管理游戏对象:创建、修改、删除、查找和组件操作。
47+
* `manage_material`: 管理材质:创建、设置属性、分配给渲染器以及查询材质信息。
4748
* `manage_prefabs`: 执行预制件操作(创建、修改、删除等)。
4849
* `manage_scene`: 管理场景(加载、保存、创建、获取层次结构等)。
4950
* `manage_script`: 传统脚本操作的兼容性路由器(创建、读取、删除)。建议使用 `apply_text_edits``script_apply_edits` 进行编辑。

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ MCP for Unity acts as a bridge, allowing AI assistants (like Claude, Cursor) to
4646
* `manage_asset`: Performs asset operations (import, create, modify, delete, etc.).
4747
* `manage_editor`: Controls and queries the editor's state and settings.
4848
* `manage_gameobject`: Manages GameObjects: create, modify, delete, find, and component operations.
49+
* `manage_material`: Manages materials: create, set properties, colors, assign to renderers, and query material info.
4950
* `manage_prefabs`: Performs prefab operations (create, modify, delete, etc.).
5051
* `manage_scene`: Manages scenes (load, save, create, get hierarchy, etc.).
5152
* `manage_script`: Compatibility router for legacy script operations (create, read, delete). Prefer `apply_text_edits` or `script_apply_edits` for edits.

0 commit comments

Comments
 (0)