跳转至

ResourceLoader

继承

Object

简要描述

此单例用于加载资源文件。

描述

此单例用于从文件系统加载资源文件。

它使用在引擎中注册的许多ResourceFormatLoader(./ResourceFormatLoader.md)类(内置的或从插件的)将文件加载到内存中,并将它们转换为引擎可以使用的格式。

IVRScript具有简化的@内置方法,该方法可以在大多数情况下使用,而对于更高级的场景,可以使用[ResourceLoader]。

方法

返回值类型 方法名称
bool exists(path: String, type_hint: String = "")
PoolStringArray get_dependencies(path: String)
PoolStringArray get_recognized_extensions_for_type(type: String)
bool has(path: String)
bool has_cached(path: String)
Resource load(path: String, type_hint: String = "", no_cache: bool = false)
ResourceInteractiveLoader load_interactive(path: String, type_hint: String = "")
void set_abort_on_missing_resources(abort: bool)

方法说明

  • exists exists(path: String, type_hint: String = "")

返回给定的路径是否存在资源。

可选的type_hint可用于进一步指定ResourceFormatLoader(./ResourceFormatLoader.md)应该处理的Resource(#method-has_cached)类型。


  • get_dependencies get_dependencies(path: String)

返回给定path上资源的依赖关系。


  • get_recognized_extensions_for_type get_recognized_extensions_for_type(type: String)

返回资源类型的注册扩展列表。


  • has has(path: String)

*不推荐使用的方法。*改用has_cachedexist


  • has_cached has_cached(path: String)

返回给定path是否是缓存的资源。

引擎加载资源后,会将其缓存在内存中以加快访问速度,以后对load或[load_interactive]方法的调用将使用缓存的版本。可以通过在同一路径的新资源上使用[Resource.take_over_path]来覆盖缓存的资源。


  • load load(path: String, type_hint: String = "", no_cache: bool = false)

加载给定path的资源,并缓存其结果用于进一步访问。

按顺序查询已注册的ResourceFormatLoader(./ResourceFormatLoader.md),以找到可以处理文件扩展名的第一个,然后尝试加载。

可选的type_hint可用于进一步指定ResourceFormatLoader(./ResourceFormatLoader.md)应该处理的Resource(#method-has_cached)类型。如果加载失败,还将尝试其余的ResourceFormatLoaders。

如果no_cachetrue,则将绕过资源缓存,并且将重新加载资源。

如果没有ResourceFormatLoader可以处理该文件,则返回一个空资源。


  • load_interactive load_interactive(path: String, type_hint: String = "")

开始以交互方式加载资源。返回[ResourceInteractiveLoader]对象,并依次调用其[ResourceInteractiveLoader.poll]方法以加载块。

可选的type_hint可用于进一步指定ResourceFormatLoader(./ResourceFormatLoader.md)应该处理的Resource(#method-has_cached)类型。


  • set_abort_on_missing_resources set_abort_on_missing_resources(abort: bool)

更改缺少子资源的行为。默认行为是中止加载。