4.3 KiB
4.3 KiB
title, type, tags, date
| title | type | tags | date | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Godot Gameplay Scripter Agent Personality | source |
|
2026-05-02 |
Source File
Summary(用中文描述)
- 核心主题:Godot 4 游戏玩法脚本专家 AI Agent 人格规范,专注于用 GDScript 2.0 和 C# 构建类型安全、信号驱动的游戏系统
- 问题域:游戏开发中如何避免 GDScript 动态类型的运行时错误、实现系统间松耦合通信、保持场景树可维护性
- 方法/机制:静态类型强制 + 强类型信号架构 + 组合优于继承 + Autoload 事件总线
- 结论/价值:提供一套完整的 Godot 4 游戏玩法系统开发规范,使代码在大型项目中仍可维护和测试
Key Claims(用中文描述)
- GDScript 信号必须使用
snake_case且携带类型化参数——携带 Variant 的未类型化信号是运行时错误的根源 - GDScript 2.0 中每个变量、函数参数和返回值必须显式类型声明——生产代码中出现未类型化的
var会导致难以追踪的 bug - 场景组合优于继承:向节点附加
HealthComponent比CharacterWithHealth基类更灵活且更可测试 - Autoload 仅用于真正的全局状态(设置/存档/事件总线)——将游戏逻辑放入 Autoload 会导致无法独立实例化和垃圾回收
- 场景必须可独立运行(按 F6)——假设父节点上下文的场景在集成时会产生级联错误
Key Quotes
"Signals must carry typed parameters — never emit untyped Variant unless interfacing with legacy code." — 信号类型安全原则 "Prefer composition over inheritance: a HealthComponent node attached as a child is better than a CharacterWithHealth base class." — 节点组合哲学 "Autoloads are singletons — use them only for genuine cross-scene global state: settings, save data, event buses, input maps." — Autoload 使用规范 "Test every scene in isolation by running it directly (F6) — it must not crash without a parent context." — 场景隔离测试原则
Key Concepts
- GDScript-2.0:Godot 4 的脚本语言,支持静态类型声明、类型推断(
:=)、强类型数组(Array[Type]) - TypedSignals:携带显式类型参数的信号(
signal health_changed(new_health: float)),而非 Variant 类型 - CompositionOverInheritance:通过组合节点(HealthComponent/MovementComponent)实现行为,而非继承层次
- EventBus:Autoload 事件总线(EventBus.gd),用于跨场景解耦通信,避免直接节点引用
- StaticTyping:GDScript 2.0 强制显式类型声明,消除运行时类型错误
- GDExtension:使用 C++ 编写性能关键系统并暴露给 GDScript 的原生扩展机制
- RenderingServer:Godot 低层渲染 API,用于绕过场景树开销实现高效 2D/3D 渲染
- SceneTreeLifecycle:
_ready()初始化、_exit_tree()清理、queue_free()安全删除的节点生命周期管理规范
Key Entities
- GodotGameplayScripter:本 Agent 身份——Godot 4 游戏玩法脚本专家,强调类型安全、信号完整性和组合架构
- GodotEngine:Godot 4 游戏引擎,支持 GDScript 2.0、C#、GDExtension 多语言生态
- GDScript:Godot 官方脚本语言,GDScript 2.0 引入静态类型支持
- CSharpGodot:Godot 的 C# 集成,使用
[Signal]委托模式和EmitSignal(SignalName.X, ...)调用
Connections
- GodotGameplayScripter ← builds_with ← GDScript-2.0
- GodotGameplayScripter ← builds_with ← CSharpGodot
- TypedSignals ← enables ← EventBus
- CompositionOverInheritance ← enables ← TypedSignals
- StaticTyping ← enforces ← GDScript-2.0
- GodotGameplayScripter ← complements ← GodotShaderDeveloper
- GodotGameplayScripter ← complements ← GodotMultiplayerEngineer
Contradictions
- 与 UnrealSystemsEngineer 冲突:
- 冲突点:游戏逻辑放置位置(Autoload vs Actor/C++ 类)
- 当前观点:游戏逻辑不得放入 Autoload,应封装在可实例化的节点组件中
- 对方观点:Unreal 中游戏逻辑倾向于放置在 Actor/Component 层次,Autoload 在 Godot 中仅作服务定位器使用