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.

ResourceSaver

繼承: Object

用於將 Resource 保存到檔案系統的單例。

說明

用於將資源型別保存到檔案系統的單例。

它會使用在引擎中註冊的(內建或外掛程式)ResourceFormatSaver 將資來源資料保存為文本檔案(如 .tres.tscn)或二進位檔案(如 .res.scn)。

方法

void

add_resource_format_saver(format_saver: ResourceFormatSaver, at_front: bool = false)

PackedStringArray

get_recognized_extensions(type: Resource)

int

get_resource_id_for_path(path: String, generate: bool = false)

void

remove_resource_format_saver(format_saver: ResourceFormatSaver)

Error

save(resource: Resource, path: String = "", flags: BitField[SaverFlags] = 0)

Error

set_uid(resource: String, uid: int)


列舉

flags SaverFlags: 🔗

SaverFlags FLAG_NONE = 0

沒有資源保存選項。

SaverFlags FLAG_RELATIVE_PATHS = 1

用相對於使用該資源的場景的路徑來保存該資源。

SaverFlags FLAG_BUNDLE_RESOURCES = 2

捆綁外部資源。

SaverFlags FLAG_CHANGE_PATH = 4

更改已保存資源的 Resource.resource_path 以配對其新位置。

SaverFlags FLAG_OMIT_EDITOR_PROPERTIES = 8

不要保存編輯器特定的中繼資料(由其 __editor 前綴標識)。

SaverFlags FLAG_SAVE_BIG_ENDIAN = 16

保存為大端序(見 FileAccess.big_endian)。

SaverFlags FLAG_COMPRESS = 32

在保存時使用 FileAccess.COMPRESSION_ZSTD 壓縮資源。僅適用於二進位資源型別。

SaverFlags FLAG_REPLACE_SUBRESOURCE_PATHS = 64

接管保存的子資源的路徑(見 Resource.take_over_path())。


方法說明

void add_resource_format_saver(format_saver: ResourceFormatSaver, at_front: bool = false) 🔗

註冊一個新的 ResourceFormatSaver。 ResourceSaver 將使用 ResourceFormatSaver,如 save() 中所述。

對於用 GDScript 編寫的 ResourceFormatSaver,此方法將隱式執行(詳情見 ResourceFormatSaver)。


PackedStringArray get_recognized_extensions(type: Resource) 🔗

返回可用於保存給定型別的資源的擴充列表。


int get_resource_id_for_path(path: String, generate: bool = false) 🔗

Returns the resource ID for the given path. If generate is true, a new resource ID will be generated if one for the path is not found. If generate is false and the path is not found, ResourceUID.INVALID_ID is returned.


void remove_resource_format_saver(format_saver: ResourceFormatSaver) 🔗

取消註冊給定的 ResourceFormatSaver


Error save(resource: Resource, path: String = "", flags: BitField[SaverFlags] = 0) 🔗

Saves a resource to disk to the given path, using a ResourceFormatSaver that recognizes the resource object. If path is empty, ResourceSaver will try to use Resource.resource_path.

The flags bitmask can be specified to customize the save behavior.

Returns @GlobalScope.OK on success.

Note: When the project is running, any generated UID associated with the resource will not be saved as the required code is only executed in editor mode.


Error set_uid(resource: String, uid: int) 🔗

Sets the UID of the given resource path to uid. You can generate a new UID using ResourceUID.create_id().

Since resources will normally get a UID automatically, this method is only useful in very specific cases.