feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2026-01-07 13:33:20 +08:00
|
|
|
using MCPForUnity.Editor.Tools;
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using UnityEditor;
|
2026-01-07 13:33:20 +08:00
|
|
|
using UnityEngine;
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
|
|
|
|
|
namespace MCPForUnity.Editor.Helpers
|
|
|
|
|
{
|
|
|
|
|
public static class MaterialOps
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Applies a set of properties (JObject) to a material, handling aliases and structured formats.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool ApplyProperties(Material mat, JObject properties, JsonSerializer serializer)
|
|
|
|
|
{
|
|
|
|
|
if (mat == null || properties == null)
|
|
|
|
|
return false;
|
|
|
|
|
bool modified = false;
|
|
|
|
|
|
|
|
|
|
// Helper for case-insensitive lookup
|
|
|
|
|
JToken GetValue(string key)
|
|
|
|
|
{
|
|
|
|
|
return properties.Properties()
|
|
|
|
|
.FirstOrDefault(p => string.Equals(p.Name, key, StringComparison.OrdinalIgnoreCase))?.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Structured / Legacy Format Handling ---
|
|
|
|
|
// Example: Set shader
|
|
|
|
|
var shaderToken = GetValue("shader");
|
|
|
|
|
if (shaderToken?.Type == JTokenType.String)
|
|
|
|
|
{
|
|
|
|
|
string shaderRequest = shaderToken.ToString();
|
|
|
|
|
// Set shader
|
|
|
|
|
Shader newShader = RenderPipelineUtility.ResolveShader(shaderRequest);
|
|
|
|
|
if (newShader != null && mat.shader != newShader)
|
|
|
|
|
{
|
|
|
|
|
mat.shader = newShader;
|
|
|
|
|
modified = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example: Set color property (structured)
|
|
|
|
|
var colorToken = GetValue("color");
|
|
|
|
|
if (colorToken is JObject colorProps)
|
|
|
|
|
{
|
|
|
|
|
string propName = colorProps["name"]?.ToString() ?? GetMainColorPropertyName(mat);
|
|
|
|
|
if (colorProps["value"] is JArray colArr && colArr.Count >= 3)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Color newColor = ParseColor(colArr, serializer);
|
|
|
|
|
if (mat.HasProperty(propName))
|
|
|
|
|
{
|
|
|
|
|
if (mat.GetColor(propName) != newColor)
|
|
|
|
|
{
|
|
|
|
|
mat.SetColor(propName, newColor);
|
|
|
|
|
modified = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2026-01-07 13:33:20 +08:00
|
|
|
McpLog.Warn($"[MaterialOps] Failed to parse color for property '{propName}': {ex.Message}");
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (colorToken is JArray colorArr) // Structured shorthand
|
|
|
|
|
{
|
|
|
|
|
string propName = GetMainColorPropertyName(mat);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Color newColor = ParseColor(colorArr, serializer);
|
|
|
|
|
if (mat.HasProperty(propName) && mat.GetColor(propName) != newColor)
|
|
|
|
|
{
|
|
|
|
|
mat.SetColor(propName, newColor);
|
|
|
|
|
modified = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2026-01-07 13:33:20 +08:00
|
|
|
McpLog.Warn($"[MaterialOps] Failed to parse color array: {ex.Message}");
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example: Set float property (structured)
|
|
|
|
|
var floatToken = GetValue("float");
|
|
|
|
|
if (floatToken is JObject floatProps)
|
|
|
|
|
{
|
|
|
|
|
string propName = floatProps["name"]?.ToString();
|
|
|
|
|
if (!string.IsNullOrEmpty(propName) &&
|
|
|
|
|
(floatProps["value"]?.Type == JTokenType.Float || floatProps["value"]?.Type == JTokenType.Integer))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
float newVal = floatProps["value"].ToObject<float>();
|
|
|
|
|
if (mat.HasProperty(propName) && mat.GetFloat(propName) != newVal)
|
|
|
|
|
{
|
|
|
|
|
mat.SetFloat(propName, newVal);
|
|
|
|
|
modified = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2026-01-07 13:33:20 +08:00
|
|
|
McpLog.Warn($"[MaterialOps] Failed to set float property '{propName}': {ex.Message}");
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example: Set texture property (structured)
|
|
|
|
|
{
|
|
|
|
|
var texToken = GetValue("texture");
|
|
|
|
|
if (texToken is JObject texProps)
|
|
|
|
|
{
|
|
|
|
|
string rawName = (texProps["name"] ?? texProps["Name"])?.ToString();
|
|
|
|
|
string texPath = (texProps["path"] ?? texProps["Path"])?.ToString();
|
|
|
|
|
if (!string.IsNullOrEmpty(texPath))
|
|
|
|
|
{
|
|
|
|
|
var sanitizedPath = AssetPathUtility.SanitizeAssetPath(texPath);
|
|
|
|
|
var newTex = AssetDatabase.LoadAssetAtPath<Texture>(sanitizedPath);
|
|
|
|
|
// Use ResolvePropertyName to handle aliases even for structured texture names
|
|
|
|
|
string candidateName = string.IsNullOrEmpty(rawName) ? "_BaseMap" : rawName;
|
|
|
|
|
string targetProp = ResolvePropertyName(mat, candidateName);
|
2026-01-07 13:33:20 +08:00
|
|
|
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
if (!string.IsNullOrEmpty(targetProp) && mat.HasProperty(targetProp))
|
|
|
|
|
{
|
|
|
|
|
if (mat.GetTexture(targetProp) != newTex)
|
|
|
|
|
{
|
|
|
|
|
mat.SetTexture(targetProp, newTex);
|
|
|
|
|
modified = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Direct Property Assignment (Flexible) ---
|
|
|
|
|
var reservedKeys = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "shader", "color", "float", "texture" };
|
|
|
|
|
|
|
|
|
|
foreach (var prop in properties.Properties())
|
|
|
|
|
{
|
|
|
|
|
if (reservedKeys.Contains(prop.Name)) continue;
|
|
|
|
|
string shaderProp = ResolvePropertyName(mat, prop.Name);
|
|
|
|
|
JToken v = prop.Value;
|
|
|
|
|
|
|
|
|
|
if (TrySetShaderProperty(mat, shaderProp, v, serializer))
|
|
|
|
|
{
|
|
|
|
|
modified = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return modified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Resolves common property aliases (e.g. "metallic" -> "_Metallic").
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string ResolvePropertyName(Material mat, string name)
|
|
|
|
|
{
|
|
|
|
|
if (mat == null || string.IsNullOrEmpty(name)) return name;
|
|
|
|
|
string[] candidates;
|
|
|
|
|
var lower = name.ToLowerInvariant();
|
|
|
|
|
switch (lower)
|
|
|
|
|
{
|
|
|
|
|
case "_color": candidates = new[] { "_Color", "_BaseColor" }; break;
|
|
|
|
|
case "_basecolor": candidates = new[] { "_BaseColor", "_Color" }; break;
|
|
|
|
|
case "_maintex": candidates = new[] { "_MainTex", "_BaseMap" }; break;
|
|
|
|
|
case "_basemap": candidates = new[] { "_BaseMap", "_MainTex" }; break;
|
|
|
|
|
case "_glossiness": candidates = new[] { "_Glossiness", "_Smoothness" }; break;
|
|
|
|
|
case "_smoothness": candidates = new[] { "_Smoothness", "_Glossiness" }; break;
|
|
|
|
|
// Friendly names → shader property names
|
|
|
|
|
case "metallic": candidates = new[] { "_Metallic" }; break;
|
|
|
|
|
case "smoothness": candidates = new[] { "_Smoothness", "_Glossiness" }; break;
|
|
|
|
|
case "albedo": candidates = new[] { "_BaseMap", "_MainTex" }; break;
|
|
|
|
|
default: candidates = new[] { name }; break; // keep original as-is
|
|
|
|
|
}
|
|
|
|
|
foreach (var candidate in candidates)
|
|
|
|
|
{
|
|
|
|
|
if (mat.HasProperty(candidate)) return candidate;
|
|
|
|
|
}
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Auto-detects the main color property name for a material's shader.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string GetMainColorPropertyName(Material mat)
|
|
|
|
|
{
|
|
|
|
|
if (mat == null || mat.shader == null)
|
|
|
|
|
return "_Color";
|
|
|
|
|
|
|
|
|
|
string[] commonColorProps = { "_BaseColor", "_Color", "_MainColor", "_Tint", "_TintColor" };
|
|
|
|
|
foreach (var prop in commonColorProps)
|
|
|
|
|
{
|
|
|
|
|
if (mat.HasProperty(prop))
|
|
|
|
|
return prop;
|
|
|
|
|
}
|
|
|
|
|
return "_Color";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tries to set a shader property on a material based on a JToken value.
|
|
|
|
|
/// Handles Colors, Vectors, Floats, Ints, Booleans, and Textures.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool TrySetShaderProperty(Material material, string propertyName, JToken value, JsonSerializer serializer)
|
|
|
|
|
{
|
|
|
|
|
if (material == null || string.IsNullOrEmpty(propertyName) || value == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Handle stringified JSON
|
|
|
|
|
if (value.Type == JTokenType.String)
|
|
|
|
|
{
|
|
|
|
|
string s = value.ToString();
|
|
|
|
|
if (s.TrimStart().StartsWith("[") || s.TrimStart().StartsWith("{"))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
JToken parsed = JToken.Parse(s);
|
|
|
|
|
return TrySetShaderProperty(material, propertyName, parsed, serializer);
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use the serializer to convert the JToken value first
|
|
|
|
|
if (value is JArray jArray)
|
|
|
|
|
{
|
|
|
|
|
if (jArray.Count == 4)
|
|
|
|
|
{
|
|
|
|
|
if (material.HasProperty(propertyName))
|
|
|
|
|
{
|
2026-01-07 13:33:20 +08:00
|
|
|
try { material.SetColor(propertyName, ParseColor(value, serializer)); return true; }
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
// Log at Debug level since we'll try other conversions
|
2026-01-07 13:33:20 +08:00
|
|
|
McpLog.Info($"[MaterialOps] SetColor attempt for '{propertyName}' failed: {ex.Message}");
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-07 13:33:20 +08:00
|
|
|
try { Vector4 vec = value.ToObject<Vector4>(serializer); material.SetVector(propertyName, vec); return true; }
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
McpLog.Info($"[MaterialOps] SetVector (Vec4) attempt for '{propertyName}' failed: {ex.Message}");
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (jArray.Count == 3)
|
|
|
|
|
{
|
|
|
|
|
if (material.HasProperty(propertyName))
|
|
|
|
|
{
|
2026-01-07 13:33:20 +08:00
|
|
|
try { material.SetColor(propertyName, ParseColor(value, serializer)); return true; }
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
McpLog.Info($"[MaterialOps] SetColor (Vec3) attempt for '{propertyName}' failed: {ex.Message}");
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (jArray.Count == 2)
|
|
|
|
|
{
|
|
|
|
|
if (material.HasProperty(propertyName))
|
|
|
|
|
{
|
2026-01-07 13:33:20 +08:00
|
|
|
try { Vector2 vec = value.ToObject<Vector2>(serializer); material.SetVector(propertyName, vec); return true; }
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
McpLog.Info($"[MaterialOps] SetVector (Vec2) attempt for '{propertyName}' failed: {ex.Message}");
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (value.Type == JTokenType.Float || value.Type == JTokenType.Integer)
|
|
|
|
|
{
|
|
|
|
|
if (!material.HasProperty(propertyName))
|
|
|
|
|
return false;
|
|
|
|
|
|
2026-01-07 13:33:20 +08:00
|
|
|
try { material.SetFloat(propertyName, value.ToObject<float>(serializer)); return true; }
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2026-01-07 13:33:20 +08:00
|
|
|
McpLog.Info($"[MaterialOps] SetFloat attempt for '{propertyName}' failed: {ex.Message}");
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (value.Type == JTokenType.Boolean)
|
|
|
|
|
{
|
|
|
|
|
if (!material.HasProperty(propertyName))
|
|
|
|
|
return false;
|
|
|
|
|
|
2026-01-07 13:33:20 +08:00
|
|
|
try { material.SetFloat(propertyName, value.ToObject<bool>(serializer) ? 1f : 0f); return true; }
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2026-01-07 13:33:20 +08:00
|
|
|
McpLog.Info($"[MaterialOps] SetFloat (bool) attempt for '{propertyName}' failed: {ex.Message}");
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (value.Type == JTokenType.String)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Try loading as asset path first (most common case for strings in this context)
|
|
|
|
|
string path = value.ToString();
|
|
|
|
|
if (!string.IsNullOrEmpty(path) && path.Contains("/")) // Heuristic: paths usually have slashes
|
|
|
|
|
{
|
2026-01-07 13:33:20 +08:00
|
|
|
// We need to handle texture assignment here.
|
|
|
|
|
// Since we don't have easy access to AssetDatabase here directly without using UnityEditor namespace (which is imported),
|
|
|
|
|
// we can try to load it.
|
|
|
|
|
var sanitizedPath = AssetPathUtility.SanitizeAssetPath(path);
|
|
|
|
|
Texture tex = AssetDatabase.LoadAssetAtPath<Texture>(sanitizedPath);
|
|
|
|
|
if (tex != null && material.HasProperty(propertyName))
|
|
|
|
|
{
|
|
|
|
|
material.SetTexture(propertyName, tex);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
McpLog.Warn($"SetTexture (string path) for '{propertyName}' failed: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-07 13:33:20 +08:00
|
|
|
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
if (value.Type == JTokenType.Object)
|
|
|
|
|
{
|
2026-01-07 13:33:20 +08:00
|
|
|
try
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
{
|
|
|
|
|
Texture texture = value.ToObject<Texture>(serializer);
|
|
|
|
|
if (texture != null && material.HasProperty(propertyName))
|
|
|
|
|
{
|
|
|
|
|
material.SetTexture(propertyName, texture);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
McpLog.Warn($"SetTexture (object) for '{propertyName}' failed: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-07 13:33:20 +08:00
|
|
|
McpLog.Warn(
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
$"[MaterialOps] Unsupported or failed conversion for material property '{propertyName}' from value: {value.ToString(Formatting.None)}"
|
|
|
|
|
);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Helper to parse color from JToken (array or object).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Color ParseColor(JToken token, JsonSerializer serializer)
|
|
|
|
|
{
|
|
|
|
|
if (token.Type == JTokenType.String)
|
|
|
|
|
{
|
|
|
|
|
string s = token.ToString();
|
|
|
|
|
if (s.TrimStart().StartsWith("[") || s.TrimStart().StartsWith("{"))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return ParseColor(JToken.Parse(s), serializer);
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (token is JArray jArray)
|
|
|
|
|
{
|
|
|
|
|
if (jArray.Count == 4)
|
|
|
|
|
{
|
|
|
|
|
return new Color(
|
|
|
|
|
(float)jArray[0],
|
|
|
|
|
(float)jArray[1],
|
|
|
|
|
(float)jArray[2],
|
|
|
|
|
(float)jArray[3]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else if (jArray.Count == 3)
|
|
|
|
|
{
|
|
|
|
|
return new Color(
|
|
|
|
|
(float)jArray[0],
|
|
|
|
|
(float)jArray[1],
|
|
|
|
|
(float)jArray[2],
|
|
|
|
|
1f
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Color array must have 3 or 4 elements.");
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-07 13:33:20 +08:00
|
|
|
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return token.ToObject<Color>(serializer);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2026-01-07 13:33:20 +08:00
|
|
|
McpLog.Warn($"[MaterialOps] Failed to parse color from token: {ex.Message}");
|
feat: Add `manage_material` tool for dedicated material manipulation (#440)
* WIP: Material management tool implementation and tests
- Add ManageMaterial tool for creating and modifying materials
- Add MaterialOps helper for material property operations
- Add comprehensive test suite for material management
- Add string parameter parsing support for material properties
- Update related tools (ManageGameObject, manage_asset, etc.)
- Add test materials and scenes for material testing
* refactor: unify material property logic into MaterialOps
- Move and logic from to
- Update to delegate to
- Update to use enhanced for creation and property setting
- Add texture path loading support to
* Add parameter aliasing support: accept 'name' as alias for 'target' in manage_gameobject modify action
* Refactor ManageMaterial and fix code review issues
- Fix Python server tools (redundant imports, exception handling, string formatting)
- Clean up documentation and error reports
- Improve ManageMaterial.cs (overwrite checks, error handling)
- Enhance MaterialOps.cs (robustness, logging, dead code removal)
- Update tests (assertions, unused imports)
- Fix manifest.json relative path
- Remove temporary test artifacts and manual setup scripts
* Remove test scene
* remove extra mat
* Remove unnecessary SceneTemplateSettings.json
* Remove unnecessary SceneTemplateSettings.json
* Fix MaterialOps issues
* Fix: Case-insensitive material property lookup and missing HasProperty checks
* Rabbit fixes
* Improve material ops logging and test coverage
* Fix: NormalizePath now handles backslashes correctly using AssetPathUtility
* Fix: Address multiple nitpicks (test robustness, shader resolution, HasProperty checks)
* 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
* Fix ManageMaterial shader reflection for Unity 6 and improve texture logging
2025-12-08 11:39:52 +08:00
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|