Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
GD0202:信号的委托签名参数不受支持
规则 ID |
GD0202 |
类别 |
用法 |
修复是破坏性的还是非破坏性的 |
破坏性的 - 如果参数类型发生改变 非破坏性的 - 如果 |
默认启用 |
是 |
原因
当用 [Signal]
属性注解的委托的参数预期为 Variant 兼容类型 时,但为其指定了不受支持的类型。
规则说明
每个信号参数必须与变体兼容,以便在发出信号和调用回调时可以对其进行编组。
class SomeType { }
// SomeType is not a valid parameter type because it doesn't derive from GodotObject,
// so it's not compatible with Variant.
public void InvalidSignalEventHandler(SomeType someType);
// System.Int32 is a valid type because it's compatible with Variant.
public void ValidSignalEventHandler(int someInt);
查看 C# 信号文档以获取有关如何声明和使用信号的更多信息。
如何解决违规情况
要修复该规则的违规情况,请将参数类型更改为与 Variant 兼容,或从委托中移除 [Signal]
属性。请注意,移除该属性将意味着该信号未被注册。
小技巧
如果信号不需要与 Godot 交互,请考虑直接使用 C# 事件。纯 C# 事件允许你使用任何 C# 类型作为其参数。
何时抑制警告
不要抑制该规则的警告。带有无法编组参数的信号委托,将在发出信号或调用回调时,导致运行时错误。