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

1.0 KiB

GFramework.Godot.SourceGenerators

面向 Godot 场景的源码生成扩展模块,减少模板代码。

主要功能

  • 与 Godot 场景相关的编译期生成能力
  • 基于 Roslyn 的增量生成器实现
  • [GetNode] 字段注入,减少 _Ready() 里的 GetNode<T>() 样板代码

使用建议

  • 仅在 Godot + C# 项目中启用
  • 非 Godot 项目可只使用 GFramework.SourceGenerators

GetNode 用法

using GFramework.Godot.SourceGenerators.Abstractions;
using Godot;

public partial class TopBar : HBoxContainer
{
    [GetNode]
    private HBoxContainer _leftContainer = null!;

    [GetNode]
    private HBoxContainer _rightContainer = null!;

    public override void _Ready()
    {
        __InjectGetNodes_Generated();
        OnReadyAfterGetNode();
    }

    private void OnReadyAfterGetNode()
    {
    }
}

当未显式填写路径时,生成器会默认将字段名推导为唯一名路径:

  • _leftContainer -> %LeftContainer
  • m_rightContainer -> %RightContainer