ResourceFormatLoader

继承: RefCounted < Object

从文件加载特定的资源类型。

描述

i3D使用ResourceFormatLoaders在编辑器或导出的应用中加载资源。它们通过ResourceLoader单例自动查询,或者在加载具有内部依赖关系的资源时自动查询。每种文件类型都可以作为不同的资源类型加载,因此在引擎中注册了多个ResourceFormatLoaders。

扩展这个类允许您定义自己的加载器。请务必尊重记录的返回类型和值。您应该给它一个带有class_name的全局类名以便注册它。像内置ResourceFormatLoaders一样,它将在加载其处理类型的资源时自动调用。您也可以实现一个ResourceFormatSaver

注意:如果您需要的资源类型存在,但i3D无法加载其格式,您也可以扩展EditorImportPlugin。选择一种方式取决于格式是否适合最终导出的应用。例如,最好先将. png纹理导入为.ctexCompressedTexture2D),这样它们就可以在显卡上以更好的效率加载。

方法

bool

_exists(path: String) virtual const

PackedStringArray

_get_classes_used(path: String) virtual const

PackedStringArray

_get_dependencies(path: String, add_types: bool) virtual const

PackedStringArray

_get_recognized_extensions() virtual const

String

_get_resource_script_class(path: String) virtual const

String

_get_resource_type(path: String) virtual const

int

_get_resource_uid(path: String) virtual const

bool

_handles_type(type: StringName) virtual const

Variant

_load(path: String, original_path: String, use_sub_threads: bool, cache_mode: int) virtual const

bool

_recognize_path(path: String, type: StringName) virtual const

Error

_rename_dependencies(path: String, renames: Dictionary) virtual const


枚举

enum CacheMode: 🔗

CacheMode CACHE_MODE_IGNORE = 0

主资源(请求加载的资源)及其任何子资源都不会从缓存中检索或存储到缓存中。依赖项(外部资源)使用CACHE_MODE_REUSE加载。

CacheMode CACHE_MODE_REUSE = 1

如果存在,则从缓存中检索主资源(请求加载的资源)、子资源及其依赖项(外部资源),而不是加载。未缓存的资源被加载,然后存储到缓存中。相同的规则在依赖项树(外部资源)中递归传播。

CacheMode CACHE_MODE_REPLACE = 2

CACHE_MODE_REUSE类似,但会检查缓存中的主资源(请求加载的资源)及其每个子资源。只要加载的类型和缓存的类型匹配,缓存中已经存在的资源的数据就会从存储中刷新到已经存在的实例中。否则,它们会重新创建为全新的对象。

CacheMode CACHE_MODE_IGNORE_DEEP = 3

CACHE_MODE_IGNORE类似,但在依赖关系树(外部资源)中递归传播。

CacheMode CACHE_MODE_REPLACE_DEEP = 4

CACHE_MODE_REPLACE类似,但在依赖关系树(外部资源)中递归传播。


方法说明

bool _exists(path: String) virtual const 🔗


PackedStringArray _get_classes_used(path: String) virtual const 🔗


PackedStringArray _get_dependencies(path: String, add_types: bool) virtual const 🔗

如果实现,则获取给定资源的依赖项。如果add_typestrue,则应附加路径:: TypeName,其中TypeName是依赖项的类名。

注意:ClassDB不知道脚本定义的自定义资源类型,因此您可能只需为它们返回"Resource"


PackedStringArray _get_recognized_extensions() virtual const 🔗

获取此加载程序能够读取的文件的扩展名列表。


String _get_resource_script_class(path: String) virtual const 🔗

返回与给定path下的Resource关联的脚本类名。如果资源没有脚本或脚本不是命名类,它应该返回"


String _get_resource_type(path: String) virtual const 🔗

获取与给定路径关联的资源的类名。如果加载程序无法处理它,它应该返回""

注意:ClassDB不知道脚本定义的自定义资源类型,因此您可能只需为它们返回"Resource"


int _get_resource_uid(path: String) virtual const 🔗

应返回与给定路径关联的资源的唯一ID。如果未覆盖此方法,则会与资源文件一起生成一个. uid文件,其中包含唯一ID。


bool _handles_type(type: StringName) virtual const 🔗

说明此加载器可以加载哪个资源类。

注意:ClassDB不知道脚本定义的自定义资源类型,因此您可以为它们处理"Resource"


Variant _load(path: String, original_path: String, use_sub_threads: bool, cache_mode: int) virtual const 🔗

当引擎发现此加载器兼容时加载资源。如果加载的资源是导入的结果,original_path将以源文件为目标。成功时返回Resource对象,失败时返回Error常量。

cache_mode属性定义加载资源时是否以及如何使用或更新缓存。有关详细信息,请参阅CacheMode


bool _recognize_path(path: String, type: StringName) virtual const 🔗

指示此加载器是否应从其资源路径加载给定类型的资源。

如果未实现,则默认行为返回路径的扩展名是否在_get_recognized_extensions()提供的扩展名内,以及类型是否在_get_resource_type()提供的扩展名内。


Error _rename_dependencies(path: String, renames: Dictionary) virtual const 🔗

如果实现,则重命名给定资源中的依赖项并保存它。renames是将旧依赖项路径映射到新路径的字典{String=>String}

成功时返回@GlobalScope.OK,失败时返回Error常量。