godot-project-foundations
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseProject Foundations
项目基础
Feature-based organization, consistent naming, and version control hygiene define professional Godot projects.
基于功能的组织方式、一致的命名规范和版本控制规范是专业Godot项目的核心。
Available Scripts
可用脚本
MANDATORY - For New Projects: Before scaffolding, read- Auto-generates feature folders and .gitignore.project_bootstrapper.gd
新项目必备:在搭建项目前,请阅读——它可自动生成功能文件夹和.gitignore文件。project_bootstrapper.gd
project_bootstrapper.gd
project_bootstrapper.gd
Expert project scaffolding tool for auto-generating feature folders and .gitignore.
专业的项目搭建工具,可自动生成功能文件夹和.gitignore文件。
scene_naming_validator.gd
scene_naming_validator.gd
Scans entire project for snake_case/PascalCase violations. Run before PRs.
扫描整个项目,检查是否存在snake_case/PascalCase命名违规情况。请在提交PR前运行该脚本。
dependency_auditor.gd
dependency_auditor.gd
Detects circular scene dependencies and coupling issues. Critical for projects >50 scenes.
检测场景循环依赖和耦合问题。对于包含50个以上场景的项目至关重要。
feature_scaffolder.gd
feature_scaffolder.gd
Generates complete feature folders with base scenes, scripts, and subfolders.
Do NOT Load dependency_auditor.gd unless troubleshooting loading errors or auditing large projects.
生成完整的功能文件夹,包含基础场景、脚本和子文件夹。
请勿加载 dependency_auditor.gd,除非你在排查加载错误或审计大型项目。
NEVER Do in Project Organization
项目组织中的禁忌
- NEVER group by file type — ,
/scripts,/spritesfolders? Nightmare maintainability. Use feature-based:/sounds,/player,/enemies./ui - NEVER mix snake_case and PascalCase in files — vs
PlayerController.gd? Pick one. Official standard: snake_case for files, PascalCase for nodes.player_controller.gd - NEVER forget .gitignore — Committing folder = 100MB+ bloat + merge conflicts. ALWAYS include Godot-specific .gitignore.
.godot/ - NEVER use hardcoded get_node() paths — breaks on scene reparenting. Use
get_node("../../../Player/Sprite2D")for stable references.%SceneUniqueNames - NEVER skip .gdignore for raw assets — Design source files (,
.psd) in project root = Godot imports them. Add.blendto exclude from import process..gdignore
- 切勿按文件类型分组——比如、
/scripts、/sprites这类文件夹?维护起来简直是噩梦。请使用基于功能的分组:/sounds、/player、/enemies。/ui - 切勿在文件中混合使用snake_case和PascalCase——比如和
PlayerController.gd共存?请统一命名方式。官方标准:文件使用snake_case,节点使用PascalCase。player_controller.gd - 切勿忘记添加.gitignore——提交文件夹会导致100MB+的冗余文件以及合并冲突。务必添加针对Godot的专属.gitignore。
.godot/ - 切勿使用硬编码的get_node()路径——会在场景重父化后失效。请使用
get_node("../../../Player/Sprite2D")来实现稳定的节点引用。%SceneUniqueNames - 切勿不为原始资源添加.gdignore——项目根目录中的设计源文件(如、
.psd)会被Godot导入。请添加.blend以排除这些文件的导入流程。.gdignore
1. Naming Conventions
1. 命名规范
- Files & Folders: Always use . (e.g.,
snake_case,player_controller.gd).main_menu.tscn- Exception: C# scripts should use to match class names.
PascalCase
- Exception: C# scripts should use
- Node Names: Always use (e.g.,
PascalCase,PlayerSprite).CollisionShape2D - Unique Names: Use for frequently accessed nodes to avoid brittle
%SceneUniqueNamespaths.get_node()
- 文件与文件夹:始终使用命名。(例如:
snake_case、player_controller.gd)。main_menu.tscn- 例外:C#脚本应使用,以匹配类名。
PascalCase
- 例外:C#脚本应使用
- 节点名称:始终使用(例如:
PascalCase、PlayerSprite)。CollisionShape2D - 唯一名称:对频繁访问的节点使用,避免脆弱的
%SceneUniqueNames路径。get_node()
2. Feature-Based Organization
2. 基于功能的组织方式
Instead of grouping by type (e.g., , ), group by feature (the "What", not the "How").
/scripts/spritesCorrect Structure:
/project.godot
/common/ # Global resources, themes, shared scripts
/entities/
/player/ # Everything related to player
player.tscn
player.gd
player_sprite.png
/enemy/
/ui/
/main_menu/
/levels/
/addons/ # Third-party plugins不要按类型分组(如、),而应按功能分组(关注“是什么”,而非“怎么做”)。
/scripts/sprites正确结构:
/project.godot
/common/ # 全局资源、主题、共享脚本
/entities/
/player/ # 与玩家相关的所有内容
player.tscn
player.gd
player_sprite.png
/enemy/
/ui/
/main_menu/
/levels/
/addons/ # 第三方插件3. Version Control
3. 版本控制
- Always include a tailored for Godot (ignoring
.gitignorefolder and import artifacts)..godot/ - Use in folders that Godot should not scan/import (e.g., raw design source files).
.gdignore
- 始终添加针对Godot的专属(忽略
.gitignore文件夹和导入产物)。.godot/ - 在Godot不应扫描/导入的文件夹中使用(例如原始设计源文件所在的文件夹)。
.gdignore
Workflow: Scaffolding a New Project
工作流程:搭建新项目
When asked to "Setup a project" or "Start a new game":
- Initialize Root: Ensure exists.
project.godot - Create Core Folders:
entities/ui/levels/common/
- Setup Git: Create a comprehensive .
.gitignore - Documentation: Create a explaining the feature-based structure.
README.md
当需要“设置项目”或“启动新游戏”时:
- 初始化根目录:确保已存在。
project.godot - 创建核心文件夹:
entities/ui/levels/common/
- 配置Git:创建全面的文件。
.gitignore - 文档编写:创建,说明基于功能的项目结构。
README.md
Reference
参考资料
- Official Docs:
tutorials/best_practices/project_organization.rst - Official Docs:
tutorials/best_practices/scene_organization.rst
- 官方文档:
tutorials/best_practices/project_organization.rst - 官方文档:
tutorials/best_practices/scene_organization.rst
Related
相关内容
- Master Skill: godot-master
- 核心技能:godot-master