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...
ResourceFormatSaver
继承: RefCounted < Object
将特定资源类型保存到文件。
描述
当你从编辑器执行此操作或使用 ResourceSaver 单例时,引擎可以节省资源。这要归功于多个 ResourceFormatSaver,每个都处理自己的格式并由引擎自动调用。
默认情况下,Godot 将资源保存为 .tres
(基于文本)、.res
(二进制)或其他内置格式,但你可以选择通过扩展这个类来创建自己的格式。请务必遵守记录的返回类型和值。你应该给它一个全局类名 class_name
以便它被注册。与内置的 ResourceFormatSaver 一样,它会在保存其识别类型的资源时自动调用。你也可以实现一个 ResourceFormatLoader。
方法
_get_recognized_extensions(resource: Resource) virtual const |
|
_recognize(resource: Resource) virtual const |
|
_recognize_path(resource: Resource, path: String) virtual const |
|
方法说明
PackedStringArray _get_recognized_extensions(resource: Resource) virtual const 🔗
返回可用于保存资源对象的扩展名列表,前提是该资源对象已被识别(见 _recognize())。
bool _recognize(resource: Resource) virtual const 🔗
返回此保存程序能否保存给定的资源对象。
bool _recognize_path(resource: Resource, path: String) virtual const 🔗
如果该saver可以处理给定的保存路径,则返回true
,否则返回false
。
如果未实现该方法,则默认行为是检查路径的扩展名是否在_get_recognized_extensions()提供的范围内。
Error _save(resource: Resource, path: String, flags: int) virtual 🔗
将给定的资源对象保存到目标path
中的文件中。 flags
是一个位掩码,由SaverFlags常量组成。
成功时返回@GlobalScope.OK,失败时返回Error常量。
Error _set_uid(path: String, uid: int) virtual 🔗
为给定 path
处的资源设置新的 UID。成功时返回 @GlobalScope.OK,失败时返回 Error 常量。