匯出套件、修正檔與 Mod¶
使用例¶
通常我們會想在遊戲部署後為遊戲增加功能。
這樣的例子包含...
DLC:可在遊戲中新增功能與內容。
修正檔:用來修正存在於已出貨產品中的 Bug。
Mod:讓其他人能夠為遊戲建立內容。
這些工具可以協助開發人員在初始版本後的開發。
PCK 檔概覽¶
Godot 中通過一個 資源套件 的功能來實現該功能 (PCK 檔,副檔名 .pck
)。
優點:
漸進更新/修補
提供 DLC
提供 Mod 支援
Mod 不需要公開原始碼
專案架構更加模組化
使用者不需要換掉整個遊戲
首先,我們需要將專案匯出並發佈給玩家。接著,當之後像新增功能或內容時,就可以通過 PCK 檔來提供更新。
PCK 檔通常包含但不限於下列內容:
腳本
場景
著色器
模型
紋理
音效
音樂
其他適合匯入到遊戲內的素材
PCK 檔甚至可以是完全不同的 Godot 專案,讓原本的遊戲在執行時載入。
產生 PCK 檔¶
要將專案中所有的資源都打包到 PCK 檔中,請打開專案,並前往 [專案] -> [匯出],接著點選 [匯出 PCK/Zip]。匯出時也請確保有選擇匯出樣板。

另一種方法為 在命令行中匯出 。若輸出檔案以 PCK 或 ZIP 副檔名結尾,則匯出過程會為所選平台建置該型別的檔案。
備註
如欲於遊戲中支援 Mod,則必須讓使用者能建立類似的匯出檔案。假設原始遊戲需要特定結構的 PCK 資源,或是需要腳本有特定的介面,那麼可選擇下列其中一種方法...
開發人員必須公開所需架構/介面的文件,並讓 Mod 作者安裝 Godot Engine,接著要求 Mod 作者依照文件中定義的 API 來製作 Mod (這樣才能正常運作)。使用者接著便能以上述方法通過 Godot 內建匯出工具來製作 PCK 檔案。
The developer uses Godot to build a GUI tool for adding their exact API content to a project. This Godot tool must either run on a tools-enabled build of the engine or have access to one (distributed alongside or perhaps in the original game's files). The tool can then use the Godot executable to export a PCK file from the command line with OS.execute(). The game itself shouldn't use a tool-build of the engine (for security), so it's best to keep the modding tool and game separate.
在執行時開啟 PCK 檔¶
To import a PCK file, one uses the ProjectSettings singleton. The following example expects a “mod.pck” file in the directory of the games executable. The PCK file contains a “mod_scene.tscn” test scene in its root.
func _your_function():
# This could fail if, for example, mod.pck cannot be found.
var success = ProjectSettings.load_resource_pack("res://mod.pck")
if success:
# Now one can use the assets as if they had them in the project from the start.
var imported_scene = load("res://mod_scene.tscn")
private void YourFunction()
{
// This could fail if, for example, mod.pck cannot be found.
var success = ProjectSettings.LoadResourcePack("res://mod.pck");
if (success)
{
// Now one can use the assets as if they had them in the project from the start.
var importedScene = (PackedScene)ResourceLoader.Load("res://mod_scene.tscn");
}
}
警告
預設情況下,若匯入的檔案名稱或路徑已存在於專案中,則專案中的檔案會被匯入的檔案給取代。這一點是製作 DLC 或 Mod 時需要注意的 (可以輕鬆通過工具隔離 Mod 指定 Mod 子資料夾來解決此問題)。但,這也是用來為遊戲製作修正檔的一種手段。這種 PCK 檔可以修正現在載入的 PCK 檔中的內容。
若要取消此一行為,請向 ProjectSettings.load_resource_pack() 傳入第二個參數為 false
。
備註
C# 專案,則需要先建置 DLL 並放在專案資料夾中。接著,在載入資源包前必須先這樣載入 DLL: Assembly.LoadFile("mod.dll")
總結¶
本教學說明了如何簡單地給遊戲加上 Mode、修正檔與 DLC。最重要的是該如何計劃發佈遊戲未來的內容,以及為此開發一個自定工作流程。Godot 依據開發人員選擇的方法,確保該流程順暢。