Update for PhysicsMaterial
1. Fixing to ensure both version of PhysicMaterial works, editing PhysicsMaterial properties to camelCase 2. Add example output on servermain
parent
77ed43bac5
commit
21fbac60c2
|
|
@ -8,6 +8,14 @@ using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityMcpBridge.Editor.Helpers; // For Response class
|
using UnityMcpBridge.Editor.Helpers; // For Response class
|
||||||
|
|
||||||
|
#if UNITY_6000_0_OR_NEWER
|
||||||
|
using PhysicsMaterialType = UnityEngine.PhysicsMaterial;
|
||||||
|
using PhysicsMaterialCombine = UnityEngine.PhysicsMaterialCombine;
|
||||||
|
#else
|
||||||
|
using PhysicsMaterialType = UnityEngine.PhysicMaterial;
|
||||||
|
using PhysicsMaterialCombine = UnityEngine.PhysicMaterialCombine;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace UnityMcpBridge.Editor.Tools
|
namespace UnityMcpBridge.Editor.Tools
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -179,7 +187,7 @@ namespace UnityMcpBridge.Editor.Tools
|
||||||
}
|
}
|
||||||
else if (lowerAssetType == "physicsmaterial")
|
else if (lowerAssetType == "physicsmaterial")
|
||||||
{
|
{
|
||||||
PhysicsMaterial pmat = new PhysicsMaterial();
|
PhysicsMaterialType pmat = new PhysicsMaterialType();
|
||||||
if (properties != null)
|
if (properties != null)
|
||||||
ApplyPhysicsMaterialProperties(pmat, properties);
|
ApplyPhysicsMaterialProperties(pmat, properties);
|
||||||
AssetDatabase.CreateAsset(pmat, fullPath);
|
AssetDatabase.CreateAsset(pmat, fullPath);
|
||||||
|
|
@ -959,45 +967,45 @@ namespace UnityMcpBridge.Editor.Tools
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Applies properties from JObject to a PhysicsMaterial.
|
/// Applies properties from JObject to a PhysicsMaterial.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static bool ApplyPhysicsMaterialProperties(PhysicsMaterial pmat, JObject properties)
|
private static bool ApplyPhysicsMaterialProperties(PhysicsMaterialType pmat, JObject properties)
|
||||||
{
|
{
|
||||||
if (pmat == null || properties == null)
|
if (pmat == null || properties == null)
|
||||||
return false;
|
return false;
|
||||||
bool modified = false;
|
bool modified = false;
|
||||||
|
|
||||||
// Example: Set dynamic friction
|
// Example: Set dynamic friction
|
||||||
if (properties["DynamicFriction"]?.Type == JTokenType.Float)
|
if (properties["dynamicFriction"]?.Type == JTokenType.Float)
|
||||||
{
|
{
|
||||||
float dynamicFriction = properties["DynamicFriction"].ToObject<float>();
|
float dynamicFriction = properties["dynamicFriction"].ToObject<float>();
|
||||||
pmat.dynamicFriction = dynamicFriction;
|
pmat.dynamicFriction = dynamicFriction;
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example: Set static friction
|
// Example: Set static friction
|
||||||
if (properties["StaticFriction"]?.Type == JTokenType.Float)
|
if (properties["staticFriction"]?.Type == JTokenType.Float)
|
||||||
{
|
{
|
||||||
float staticFriction = properties["StaticFriction"].ToObject<float>();
|
float staticFriction = properties["staticFriction"].ToObject<float>();
|
||||||
pmat.staticFriction = staticFriction;
|
pmat.staticFriction = staticFriction;
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example: Set bounciness
|
// Example: Set bounciness
|
||||||
if (properties["Bounciness"]?.Type == JTokenType.Float)
|
if (properties["bounciness"]?.Type == JTokenType.Float)
|
||||||
{
|
{
|
||||||
float bounciness = properties["Bounciness"].ToObject<float>();
|
float bounciness = properties["bounciness"].ToObject<float>();
|
||||||
pmat.bounciness = bounciness;
|
pmat.bounciness = bounciness;
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> averageList = new List<String>{"ave", "Ave", "average", "Average"};
|
List<String> averageList = new List<String> { "ave", "Ave", "average", "Average" };
|
||||||
List<String> multiplyList = new List<String>{"mul", "Mul", "mult", "Mult", "multiply", "Multiply"};
|
List<String> multiplyList = new List<String> { "mul", "Mul", "mult", "Mult", "multiply", "Multiply" };
|
||||||
List<String> minimumList = new List<String>{"min", "Min", "minimum", "Minimum"};
|
List<String> minimumList = new List<String> { "min", "Min", "minimum", "Minimum" };
|
||||||
List<String> maximumList = new List<String>{"max", "Max", "maximum", "Maximum"};
|
List<String> maximumList = new List<String> { "max", "Max", "maximum", "Maximum" };
|
||||||
|
|
||||||
// Example: Set friction combine
|
// Example: Set friction combine
|
||||||
if (properties["FrictionCombine"]?.Type == JTokenType.String)
|
if (properties["frictionCombine"]?.Type == JTokenType.String)
|
||||||
{
|
{
|
||||||
string frictionCombine = properties["FrictionCombine"].ToString();
|
string frictionCombine = properties["frictionCombine"].ToString();
|
||||||
if (averageList.Contains(frictionCombine))
|
if (averageList.Contains(frictionCombine))
|
||||||
pmat.frictionCombine = PhysicsMaterialCombine.Average;
|
pmat.frictionCombine = PhysicsMaterialCombine.Average;
|
||||||
else if (multiplyList.Contains(frictionCombine))
|
else if (multiplyList.Contains(frictionCombine))
|
||||||
|
|
@ -1010,9 +1018,9 @@ namespace UnityMcpBridge.Editor.Tools
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example: Set bounce combine
|
// Example: Set bounce combine
|
||||||
if (properties["BounceCombine"]?.Type == JTokenType.String)
|
if (properties["bounceCombine"]?.Type == JTokenType.String)
|
||||||
{
|
{
|
||||||
string bounceCombine = properties["BounceCombine"].ToString();
|
string bounceCombine = properties["bounceCombine"].ToString();
|
||||||
if (averageList.Contains(bounceCombine))
|
if (averageList.Contains(bounceCombine))
|
||||||
pmat.bounceCombine = PhysicsMaterialCombine.Average;
|
pmat.bounceCombine = PhysicsMaterialCombine.Average;
|
||||||
else if (multiplyList.Contains(bounceCombine))
|
else if (multiplyList.Contains(bounceCombine))
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,9 @@ def register_manage_asset_tools(mcp: FastMCP):
|
||||||
path: Asset path (e.g., "Materials/MyMaterial.mat") or search scope.
|
path: Asset path (e.g., "Materials/MyMaterial.mat") or search scope.
|
||||||
asset_type: Asset type (e.g., 'Material', 'Folder') - required for 'create'.
|
asset_type: Asset type (e.g., 'Material', 'Folder') - required for 'create'.
|
||||||
properties: Dictionary of properties for 'create'/'modify'.
|
properties: Dictionary of properties for 'create'/'modify'.
|
||||||
|
example properties for Material: {"color": [1, 0, 0, 1], "shader": "Standard"}.
|
||||||
|
example properties for Texture: {"width": 1024, "height": 1024, "format": "RGBA32"}.
|
||||||
|
example properties for PhysicsMaterial: {"bounciness": 1.0, "staticFriction": 0.5, "dynamicFriction": 0.5}.
|
||||||
destination: Target path for 'duplicate'/'move'.
|
destination: Target path for 'duplicate'/'move'.
|
||||||
search_pattern: Search pattern (e.g., '*.prefab').
|
search_pattern: Search pattern (e.g., '*.prefab').
|
||||||
filter_*: Filters for search (type, date).
|
filter_*: Filters for search (type, date).
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue