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...
PCKPacker
繼承: RefCounted < Object
建立可以載入到正在運作的專案中的包。
說明
PCKPacker 可以建立打包檔案,專案執行時可以使用 ProjectSettings.load_resource_pack() 來載入打包檔案。
var packer = PCKPacker.new()
packer.pck_start("test.pck")
packer.add_file("res://text.txt", "text.txt")
packer.flush()
var packer = new PckPacker();
packer.PckStart("test.pck");
packer.AddFile("res://text.txt", "text.txt");
packer.Flush();
上面的例子中,PCKPacker 建立了打包檔案 test.pck,但後將名為 text.txt 的檔案新增到了包的根目錄。
注意:PCK 是 Godot 自有的打包檔案格式。要建立任何程式都能夠讀取的 ZIP 壓縮檔,請改用 ZIPPacker。
方法
add_file(target_path: String, source_path: String, encrypt: bool = false) |
|
add_file_from_buffer(target_path: String, data: PackedByteArray, encrypt: bool = false) |
|
add_file_removal(target_path: String) |
|
pck_start(pck_path: String, alignment: int = 32, key: String = "0000000000000000000000000000000000000000000000000000000000000000", encrypt_directory: bool = false) |
方法說明
Error add_file(target_path: String, source_path: String, encrypt: bool = false) 🔗
將 source_path 檔案新增到目前 PCK 包的內部路徑 target_path 處。target_path 不必寫 res:// 前綴,內部會將其去除。檔案內容會立即寫入到 PCK 中。
Error add_file_from_buffer(target_path: String, data: PackedByteArray, encrypt: bool = false) 🔗
將 data(資料)新增到目前 PCK 包中,其在包內的路徑為 target_path。target_path 的 res:// 前綴是可選的,會在內部被自動去除。檔案內容會被立即寫入 PCK 包中。
Error add_file_removal(target_path: String) 🔗
注冊移除 PCK 內部路徑 target_path 處的檔案。主要用於補丁。如果位於該路徑的檔案已從之前的 PCK 載入,則會被移除。target_path 不必寫 res:// 前綴,內部會將其去除。
Error flush(verbose: bool = false) 🔗
寫入檔案目錄並關閉 PCK。如果 verbose 為 true,則會將檔案清單輸出在控制台,方便除錯。
注意:PCKPacker 被釋放時會自動刷新,釋放發生在離開作用域或被賦值為 null 時。在 C# 中,使用完後必須棄置該參照,可以使用 using 語句或直接呼叫 Dispose 方法。
Error pck_start(pck_path: String, alignment: int = 32, key: String = "0000000000000000000000000000000000000000000000000000000000000000", encrypt_directory: bool = false) 🔗
在檔案路徑 pck_path 處新建 PCK 檔案。不會自動新增 .pck 檔案副檔名,因此 pck_path 中應包含該副檔名(即使副檔名不是必需的)。