Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
編輯器開發簡介
本頁將介紹:
Godot 編輯器背後的**設計決策**。
如何有效率地開發 Godot 編輯器的 C++ 程式碼。
本指南適用於現有或未來的引擎貢獻者。若要用 GDScript 建立編輯器外掛,請參閱 製作外掛程式。
也參考
如果你是 Godot 的新手,建議你在繼續閱讀之前先參考 Godot 的設計理念。由於 Godot 編輯器本身也是以 C++ 開發的 Godot 專案,因此許多引擎的設計理念同樣適用於編輯器。
技術選擇
Godot 編輯器是以 Godot 自身的算繪器與 UI 系統 繪製,不 依賴 GTK、Qt 等外部 UI 工具包。這與 Blender 等軟體有類似精神。雖然使用工具包可比較容易實作「原生」外觀,但這些工具包較為龐大,且授權條款與 Godot 不相容。
編輯器本身完全以 C++ 撰寫,不能包含任何 GDScript 或 C# 程式碼。
目錄結構
編輯器的程式碼完整地放在 Godot 原始碼儲存庫的 editor/ 資料夾中。
部分編輯器功能也會透過 modules 模組實作。有些模組僅於編輯器版本啟用,以減少匯出範本的二進位檔案大小。詳見 Godot 儲存庫的 modules/ 目錄。
編輯器中幾個重要檔案:
editor/editor_node.cpp:主要的編輯器初始化檔,相當於編輯器的「主場景」。
editor/project_manager/project_manager.cpp: Main Project Manager initialization file. Effectively the "main scene" of the Project Manager.
editor/scene/canvas_item_editor_plugin.cpp: The 2D editor viewport and related functionality (toolbar at the top, editing modes, overlaid helpers/panels, …).
editor/scene/3d/node_3d_editor_plugin.cpp: The 3D editor viewport and related functionality (toolbar at the top, editing modes, overlaid panels, …).
editor/scene/3d/node_3d_editor_gizmos.cpp: Where the 3D editor gizmos are defined and drawn. This file doesn't have a 2D counterpart as 2D gizmos are drawn by the nodes themselves.
scene/ 內的編輯器依賴
在開發編輯器功能時,有時必須修改 Godot 的 GUI 節點檔案,這些檔案位於 scene/ 目錄下。
請特別注意, 不可 在如 scene/ 等其他資料夾中引入對 editor/ 的新依賴,即使有使用 #ifdef TOOLS_ENABLED 也不例外。
為了讓程式碼結構更清晰且具備良好模組化,建議依賴順序如下:
editor/→scene/→servers/→core/
也就是說,editor/ 內的檔案可以依賴 scene/、servers/、core/,而 scene/ 可以依賴 servers/ 與 core/,但絕對不能依賴 editor/。
目前 scene/ 內仍有部分檔案依賴到 editor/,但 這些依賴正在逐步移除。
開發小技巧
為了加快開發週期,建議建立一個測試專案並在編譯完成後 從命令列開啟。如此就能避免每次啟動 Godot 都需經過專案管理器。