代码检查:参数应派生自 'Component'
此检查会报告其第一个参数不是从 UnityEngine.Component 派生的 [DrawGizmo] 方法。
Unity 期望 [DrawGizmo] 方法为静态方法,第一个参数为组件类型,第二个参数为 GizmoType。 如果第一个参数不是组件类型,Unity 将无法按预期使用该方法。
示例
在此示例中,第一个参数是 GameObject ,它不是组件。 正确的方法签名应使用组件类型,例如 Transform。
using UnityEditor;
using UnityEngine;
public class Example
{
[DrawGizmo]
public static void DrawForObject(GameObject target, GizmoType gizmoType)
{
}
}
using UnityEditor;
using UnityEngine;
public class Example
{
[DrawGizmo]
public static void DrawForObject(Transform target, GizmoType gizmoType)
{
}
}
快速修复
此检查不提供专用的快速修复。 请手动修复方法,将第一个参数更改为派生自 Component 的类型,例如 Transform、 Collider 或你自己的 MonoBehaviour。
2026年 5月 8日