GeWuYou fb14d7122c docs(style): 更新文档中的命名空间导入格式
- 将所有小写的命名空间导入更正为首字母大写格式
- 统一 GFramework 框架的命名空间引用规范
- 修复 core、ecs、godot 等模块的命名空间导入错误
- 标准化文档示例代码中的 using 语句格式
- 确保所有文档中的命名空间引用保持一致性
- 更新 global using 语句以匹配正确的命名空间格式
2026-03-10 07:18:49 +08:00

65 lines
2.0 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(GodotObject 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>
/// <param name="flags">连接标志</param>
/// <returns>当前构建器实例</returns>
public SignalBuilder To(Callable callable, GodotObject.ConnectFlags? flags = null)
{
var finalFlags = flags ?? _flags;
// 根据是否设置了标志来决定连接方式
if (finalFlags is null)
target.Connect(signal, callable);
else
target.Connect(signal, callable, (uint)finalFlags);
return this;
}
/// <summary>
/// 连接信号到指定的可调用对象并立即调用
/// </summary>
/// <param name="callable">要连接的可调用对象</param>
/// <param name="flags">连接标志</param>
/// <param name="args">调用参数</param>
/// <returns>当前构建器实例</returns>
public SignalBuilder ToAndCall(Callable callable, GodotObject.ConnectFlags? flags = null, params Variant[] args)
{
To(callable, flags);
callable.Call(args);
return this;
}
/// <summary>
/// 显式结束,返回 Node
/// </summary>
/// <returns>目标节点</returns>
public GodotObject End()
{
return target;
}
}