ResourceLoader¶
继承: Object
类别: 核心
简要说明¶
singleton用于加载资源文件。
方法¶
get_dependencies ( String path ) |
|
get_recognized_extensions_for_type ( String type ) |
|
has_cached ( String path ) |
|
load ( String path, String type_hint="", bool no_cache=false ) |
|
load_interactive ( String path, String type_hint="" ) |
|
无效 |
set_abort_on_missing_resources ( bool abort ) |
描述¶
singleton用于从文件系统加载资源文件。
它使用了很多 ResourceFormatLoader 在引擎中注册的类(内置的或从插件中注册的)将文件加载到内存中,并将其转换为引擎可以使用的格式。
gdscript简化了 @GDScript.load 在大多数情况下都可以使用的内置方法 ResourceLoader
对于更高级的场景。
方法说明¶
返回给定资源是否存在可识别的资源 path
.
可选的 type_hint
可用于进一步指定 Resource 应该由 ResourceFormatLoader .
PoolStringArray get_dependencies ( String path )
返回给定资源的依赖项 path
.
PoolStringArray get_recognized_extensions_for_type ( String type )
返回资源类型的可识别扩展名列表。
已弃用的方法。 使用 has_cached 或 exists 相反。
返回缓存资源是否可用于给定的 path
.
一旦引擎加载了一个资源,它就会缓存在内存中,以便更快地访问,并在将来调用 load 或 load_interactive 方法将使用缓存版本。缓存的资源可以通过使用 Resource.take_over_path 在同一路径的新资源上。
在给定位置加载资源 path
,缓存结果以供进一步访问。
注册的 ResourceFormatLoader 按顺序查询,以找到第一个可以处理文件扩展名的文件,然后尝试加载。如果加载失败,还将尝试其余的ResourceFormatLoader。
可选的 type_hint
可用于进一步指定 Resource 应该由 ResourceFormatLoader .
如果 no_cache
是 true
,将绕过资源缓存并重新加载资源。否则,如果缓存的资源存在,将返回该资源。
如果没有ResourceFormatLoader可以处理该文件,则返回空资源。
ResourceInteractiveLoader load_interactive ( String path, String type_hint="" )
开始以交互方式加载资源。返回的 ResourceInteractiveLoader 对象允许以高粒度加载,调用其 ResourceInteractiveLoader.poll 方法依次加载块。
可选的 type_hint
可用于进一步指定 Resource 应该由 ResourceFormatLoader .
void set_abort_on_missing_resources ( bool abort )
更改丢失子资源的行为。默认行为是中止加载。