GeWuYou 9ab09cf47b feat(godot): 添加 GetNode 源代码生成器功能
- 实现了 [GetNode] 属性用于标记 Godot 节点字段
- 创建了 GetNodeGenerator 源代码生成器自动注入节点获取逻辑
- 添加了节点路径推导和多种查找模式支持
- 集成了生成器到 Godot 脚手架模板中
- 添加了完整的诊断规则和错误提示
- 创建了单元测试验证生成器功能
- 更新了解决方案配置以包含新的测试项目
- 在 README 中添加了详细的使用文档和示例代码
2026-03-22 15:16:24 +08:00

40 lines
1.2 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.

#nullable enable
namespace GFramework.Godot.SourceGenerators.Abstractions;
/// <summary>
/// 标记 Godot 节点字段Source Generator 会为其生成节点获取逻辑。
/// </summary>
[AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
public sealed class GetNodeAttribute : Attribute
{
/// <summary>
/// 初始化 <see cref="GetNodeAttribute" /> 的新实例。
/// </summary>
public GetNodeAttribute()
{
}
/// <summary>
/// 初始化 <see cref="GetNodeAttribute" /> 的新实例,并指定节点路径。
/// </summary>
/// <param name="path">节点路径。</param>
public GetNodeAttribute(string path)
{
Path = path;
}
/// <summary>
/// 获取或设置节点路径。未设置时将根据字段名推导。
/// </summary>
public string? Path { get; set; }
/// <summary>
/// 获取或设置节点是否必填。默认为 true。
/// </summary>
public bool Required { get; set; } = true;
/// <summary>
/// 获取或设置节点查找模式。默认为 <see cref="NodeLookupMode.Auto" />。
/// </summary>
public NodeLookupMode Lookup { get; set; } = NodeLookupMode.Auto;
}