GwWuYou cacd82d7b7 refactor(signal): 优化 SignalBuilder 的 To 方法实现
- 将方法功能描述从"将信号连接到指定的处理方法"更新为"连接信号到指定的可调用对象"
- 为 To 方法添加返回值类型 SignalBuilder 以支持链式调用
- 简化连接逻辑,移除不必要的 if-else 分支
- 添加 End 方法用于返回目标节点
- 更新参数说明文档
2026-01-02 20:46:53 +08:00

46 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Godot;
namespace GFramework.Godot.extensions.signal;
/// <summary>
/// 信号连接构建器用于以流畅的方式连接Godot信号
/// </summary>
/// <param name="target">要连接信号的目标节点</param>
/// <param name="signal">要连接的信号名称</param>
public sealed class SignalBuilder(Node target, StringName signal)
{
private GodotObject.ConnectFlags? _flags;
/// <summary>
/// 设置连接标志
/// </summary>
/// <param name="flags">连接标志</param>
/// <returns>当前构建器实例</returns>
public SignalBuilder WithFlags(GodotObject.ConnectFlags flags)
{
_flags = flags;
return this;
}
/// <summary>
/// 连接信号到指定的可调用对象
/// </summary>
/// <param name="callable">要连接的可调用对象</param>
/// <returns>当前构建器实例</returns>
public SignalBuilder To(Callable callable)
{
// 根据是否设置了标志来决定连接方式
if (_flags is null)
target.Connect(signal, callable);
else
target.Connect(signal, callable, (uint)_flags);
return this;
}
/// <summary>
/// 显式结束,返回 Node
/// </summary>
/// <returns>目标节点</returns>
public Node End() => target;
}