Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions MCPForUnity/Editor/Helpers/ComponentOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,18 @@ internal static bool SetObjectReference(SerializedProperty prop, JToken value, o
return AssignObjectReference(prop, resolved, null, out error);
}

// Try as asset GUID (32-char hex string)
if (strVal.Length == 32 && IsHexString(strVal))
{
string assetPath = AssetDatabase.GUIDToAssetPath(strVal);
if (!string.IsNullOrEmpty(assetPath))
{
var resolved = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetPath);
if (resolved != null)
return AssignObjectReference(prop, resolved, null, out error);
}
}

// Fall back to scene hierarchy lookup by name.
return ResolveSceneObjectByName(prop, strVal, null, out error);
}
Expand Down Expand Up @@ -969,6 +981,16 @@ private static long GetSpriteFileId(Sprite sprite)
return 0;
}
}

private static bool IsHexString(string str)
{
foreach (char c in str)
{
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')))
return false;
}
return true;
}
}
}

8 changes: 7 additions & 1 deletion MCPForUnity/Editor/Tools/Profiler/Operations/CounterOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ void Tick()

private static readonly string[] ValidCategories = new[]
{
"Render", "Scripts", "Memory", "Physics", "Physics2D", "Animation",
"Render", "Scripts", "Memory", "Physics",
#if UNITY_2022_2_OR_NEWER
"Physics2D",
#endif
"Animation",
"Audio", "Lighting", "Network", "Gui", "UI", "Ai", "Video",
"Loading", "Input", "Vr", "Internal", "Particles", "FileIO", "VirtualTexturing"
};
Expand All @@ -125,7 +129,9 @@ void Tick()
case "scripts": return ProfilerCategory.Scripts;
case "memory": return ProfilerCategory.Memory;
case "physics": return ProfilerCategory.Physics;
#if UNITY_2022_2_OR_NEWER
case "physics2d": return ProfilerCategory.Physics2D;
#endif
case "animation": return ProfilerCategory.Animation;
case "audio": return ProfilerCategory.Audio;
case "lighting": return ProfilerCategory.Lighting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ internal static class FrameTimingOps
{
internal static object GetFrameTiming(JObject @params)
{
#if UNITY_2022_2_OR_NEWER
if (!FrameTimingManager.IsFeatureEnabled())
{
return new ErrorResponse(
"Frame Timing Stats is not enabled. "
+ "Enable it in Project Settings > Player > Other Settings > 'Frame Timing Stats', "
+ "or use a Development Build (always enabled).");
}
#endif

FrameTimingManager.CaptureFrameTimings();
var timings = new FrameTiming[1];
Expand All @@ -33,12 +35,16 @@ internal static object GetFrameTiming(JObject @params)
{
available = true,
cpu_frame_time_ms = t.cpuFrameTime,
#if UNITY_2022_2_OR_NEWER
cpu_main_thread_frame_time_ms = t.cpuMainThreadFrameTime,
cpu_main_thread_present_wait_time_ms = t.cpuMainThreadPresentWaitTime,
cpu_render_thread_frame_time_ms = t.cpuRenderThreadFrameTime,
#endif
gpu_frame_time_ms = t.gpuFrameTime,
#if UNITY_2022_2_OR_NEWER
frame_start_timestamp = t.frameStartTimestamp,
first_submit_timestamp = t.firstSubmitTimestamp,
#endif
cpu_time_present_called = t.cpuTimePresentCalled,
cpu_time_frame_complete = t.cpuTimeFrameComplete,
height_scale = t.heightScale,
Expand Down
30 changes: 30 additions & 0 deletions MCPForUnity/Editor/Tools/UnityReflect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,23 @@ private static object GetTypeInfo(ToolParams p)
});
}

// Open generic type definitions (e.g. List<T>) segfault Mono on Unity 2021.3
// in mono_metadata_generic_param_equal_internal when any member reflection is
// performed. Return minimal info using only safe property accesses.
if (type.IsGenericTypeDefinition)
{
return new SuccessResponse($"Type info for '{type.Name}'.", new
{
found = true,
name = type.Name,
full_name = type.FullName,
@namespace = type.Namespace,
assembly = type.Assembly.GetName().Name,
is_generic_type_definition = true,
hint = "Open generic type — consult docs for member details."
});
}

var flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;

var methods = type.GetMethods(flags)
Expand Down Expand Up @@ -272,6 +289,19 @@ private static object GetMemberInfo(ToolParams p)
});
}

if (type.IsGenericTypeDefinition)
{
return new SuccessResponse(
$"Open generic type '{type.Name}' — consult docs for member details.", new
{
found = false,
type_name = type.FullName,
member_name = memberName,
is_generic_type_definition = true,
hint = "Open generic type — consult docs for member details."
});
}

// Use flags without DeclaredOnly to find inherited members
var flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;

Expand Down
2 changes: 1 addition & 1 deletion Server/tests/test_cli_commands_characterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ def test_prefab_workflow_open_modify_save(self, runner, mock_config):
assert result.exit_code == 0

# Save
result = runner.invoke(prefab, ["save", "--force"])
result = runner.invoke(prefab, ["save"])
assert result.exit_code == 0

# Close
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ManageGraphicsTests
private const string TempRoot = "Assets/Temp/ManageGraphicsTests";
private bool _hasVolumeSystem;
private bool _hasURP;
private bool _hasHDRP;

[SetUp]
public void SetUp()
Expand All @@ -28,6 +29,7 @@ public void SetUp()
var data = pingResult["data"];
_hasVolumeSystem = data?.Value<bool>("hasVolumeSystem") ?? false;
_hasURP = data?.Value<bool>("hasURP") ?? false;
_hasHDRP = data?.Value<bool>("hasHDRP") ?? false;
}
}

Expand Down Expand Up @@ -72,7 +74,7 @@ public void HandleCommand_MissingAction_ReturnsError()
{
var result = ToJObject(ManageGraphics.HandleCommand(new JObject()));
Assert.IsFalse(result.Value<bool>("success"));
Assert.That(result["message"].ToString(), Does.Contain("action"));
Assert.That(result["error"].ToString(), Does.Contain("action"));
}

[Test]
Expand All @@ -81,7 +83,7 @@ public void HandleCommand_UnknownAction_ReturnsError()
var result = ToJObject(ManageGraphics.HandleCommand(
new JObject { ["action"] = "bogus_action" }));
Assert.IsFalse(result.Value<bool>("success"));
Assert.That(result["message"].ToString(), Does.Contain("Unknown action"));
Assert.That(result["error"].ToString(), Does.Contain("Unknown action"));
}

[Test]
Expand Down Expand Up @@ -539,7 +541,7 @@ public void BakeSetProbePositions_WrongComponent_ReturnsError()
["positions"] = new JArray { new JArray(0, 0, 0) }
}));
Assert.IsFalse(result.Value<bool>("success"));
Assert.That(result["message"].ToString(), Does.Contain("LightProbeGroup"));
Assert.That(result["error"].ToString(), Does.Contain("LightProbeGroup"));
}

// =====================================================================
Expand Down Expand Up @@ -598,7 +600,7 @@ public void StatsSetSceneDebug_InvalidMode_ReturnsError()
["mode"] = "InvalidMode"
}));
Assert.IsFalse(result.Value<bool>("success"));
Assert.That(result["message"].ToString(), Does.Contain("Valid:"));
Assert.That(result["error"].ToString(), Does.Contain("Valid:"));
}

// =====================================================================
Expand All @@ -618,6 +620,7 @@ public void PipelineGetInfo_ReturnsPipelineName()
[Test]
public void PipelineGetSettings_ReturnsSettings()
{
Assume.That(_hasURP || _hasHDRP, "Built-in pipeline has no settings asset — skipping.");
var result = ToJObject(ManageGraphics.HandleCommand(
new JObject { ["action"] = "pipeline_get_settings" }));
Assert.IsTrue(result.Value<bool>("success"), result.ToString());
Expand All @@ -635,7 +638,7 @@ public void PipelineSetQuality_InvalidLevel_ReturnsError()
["level"] = "NonExistentLevel"
}));
Assert.IsFalse(result.Value<bool>("success"));
Assert.That(result["message"].ToString(), Does.Contain("Available:"));
Assert.That(result["error"].ToString(), Does.Contain("Available:"));
}

// =====================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,16 +768,17 @@ public void SetCollisionMatrix_MissingParams_ReturnsError()
[Test]
public void Raycast_HitsCollider()
{
// Use an offset origin/direction to avoid hitting unrelated scene objects
var go = new GameObject("PhysTest_RayTarget");
go.transform.position = new Vector3(0, 0, 5);
go.transform.position = new Vector3(500, 500, 5);
var col = go.AddComponent<BoxCollider>();
col.size = new Vector3(10, 10, 1);
UnityEngine.Physics.SyncTransforms();

var result = ToJObject(ManagePhysics.HandleCommand(new JObject
{
["action"] = "raycast",
["origin"] = new JArray(0, 0, 0),
["origin"] = new JArray(500, 500, 0),
["direction"] = new JArray(0, 0, 1),
["max_distance"] = 100
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public void HandleCommand_UnknownAction_ReturnsError()
var result = ToJObject(ManageProBuilder.HandleCommand(paramsObj));

Assert.IsFalse(result.Value<bool>("success"), result.ToString());
Assert.That(result["error"]?.ToString() ?? result["message"]?.ToString(),
Does.Contain("Unknown action"));
var errorMsg = result["error"]?.ToString() ?? result["message"]?.ToString();
Assert.That(errorMsg, Does.Contain("Unknown action").Or.Contain("not installed"));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void Screenshot_SceneViewRejectsSupersizeAboveOne()
var response = raw as JObject ?? JObject.FromObject(raw);

Assert.IsFalse(response.Value<bool>("success"), response.ToString());
StringAssert.Contains("does not support super_size above 1", response.Value<string>("message"));
StringAssert.Contains("does not support super_size above 1", response.Value<string>("error"));
}

[Test]
Expand Down Expand Up @@ -182,7 +182,7 @@ public void Screenshot_ViewTargetAcceptedForGameView()

// Should attempt positioned capture and fail to resolve the GO — not reject the param
Assert.IsFalse(response.Value<bool>("success"), response.ToString());
StringAssert.Contains("not found", response.Value<string>("message"));
StringAssert.Contains("not found", response.Value<string>("error"));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void ModifyBuildSettings_RedirectsToManageBuild()
var result = ManageScene.HandleCommand(p);
var r = result as JObject ?? JObject.FromObject(result);
Assert.IsFalse(r.Value<bool>("success"));
Assert.IsTrue(r.Value<string>("message").Contains("manage_build"));
Assert.IsTrue(r.Value<string>("error").Contains("manage_build"));
}

[Test]
Expand Down
Loading