mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-05 22:09:56 +03:00
classref: Sync with current master branch (f87858a8f)
This commit is contained in:
@@ -14,6 +14,8 @@ ResourceFormatLoader
|
||||
|
||||
Loads a specific resource type from a file.
|
||||
|
||||
.. rst-class:: classref-introduction-group
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
@@ -23,144 +25,213 @@ Extending this class allows you to define your own loader. Be sure to respect th
|
||||
|
||||
\ **Note:** You can also extend :ref:`EditorImportPlugin<class_EditorImportPlugin>` if the resource type you need exists but Godot is unable to load its format. Choosing one way over another depends on if the format is suitable or not for the final exported game. For example, it's better to import ``.png`` textures as ``.ctex`` (:ref:`CompressedTexture2D<class_CompressedTexture2D>`) first, so they can be loaded with better efficiency on the graphics card.
|
||||
|
||||
.. rst-class:: classref-reftable-group
|
||||
|
||||
Methods
|
||||
-------
|
||||
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`bool<class_bool>` | :ref:`_exists<class_ResourceFormatLoader_method__exists>` **(** :ref:`String<class_String>` path **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`_get_classes_used<class_ResourceFormatLoader_method__get_classes_used>` **(** :ref:`String<class_String>` path **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`_get_dependencies<class_ResourceFormatLoader_method__get_dependencies>` **(** :ref:`String<class_String>` path, :ref:`bool<class_bool>` add_types **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`_get_recognized_extensions<class_ResourceFormatLoader_method__get_recognized_extensions>` **(** **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`String<class_String>` | :ref:`_get_resource_type<class_ResourceFormatLoader_method__get_resource_type>` **(** :ref:`String<class_String>` path **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`int<class_int>` | :ref:`_get_resource_uid<class_ResourceFormatLoader_method__get_resource_uid>` **(** :ref:`String<class_String>` path **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`bool<class_bool>` | :ref:`_handles_type<class_ResourceFormatLoader_method__handles_type>` **(** :ref:`StringName<class_StringName>` type **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`Variant<class_Variant>` | :ref:`_load<class_ResourceFormatLoader_method__load>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` original_path, :ref:`bool<class_bool>` use_sub_threads, :ref:`int<class_int>` cache_mode **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`bool<class_bool>` | :ref:`_recognize_path<class_ResourceFormatLoader_method__recognize_path>` **(** :ref:`String<class_String>` path, :ref:`StringName<class_StringName>` type **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`int<class_int>` | :ref:`_rename_dependencies<class_ResourceFormatLoader_method__rename_dependencies>` **(** :ref:`String<class_String>` path, :ref:`Dictionary<class_Dictionary>` renames **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
.. table::
|
||||
:widths: auto
|
||||
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`bool<class_bool>` | :ref:`_exists<class_ResourceFormatLoader_method__exists>` **(** :ref:`String<class_String>` path **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`_get_classes_used<class_ResourceFormatLoader_method__get_classes_used>` **(** :ref:`String<class_String>` path **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`_get_dependencies<class_ResourceFormatLoader_method__get_dependencies>` **(** :ref:`String<class_String>` path, :ref:`bool<class_bool>` add_types **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`_get_recognized_extensions<class_ResourceFormatLoader_method__get_recognized_extensions>` **(** **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`String<class_String>` | :ref:`_get_resource_type<class_ResourceFormatLoader_method__get_resource_type>` **(** :ref:`String<class_String>` path **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`int<class_int>` | :ref:`_get_resource_uid<class_ResourceFormatLoader_method__get_resource_uid>` **(** :ref:`String<class_String>` path **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`bool<class_bool>` | :ref:`_handles_type<class_ResourceFormatLoader_method__handles_type>` **(** :ref:`StringName<class_StringName>` type **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`Variant<class_Variant>` | :ref:`_load<class_ResourceFormatLoader_method__load>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` original_path, :ref:`bool<class_bool>` use_sub_threads, :ref:`int<class_int>` cache_mode **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`bool<class_bool>` | :ref:`_recognize_path<class_ResourceFormatLoader_method__recognize_path>` **(** :ref:`String<class_String>` path, :ref:`StringName<class_StringName>` type **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`int<class_int>` | :ref:`_rename_dependencies<class_ResourceFormatLoader_method__rename_dependencies>` **(** :ref:`String<class_String>` path, :ref:`Dictionary<class_Dictionary>` renames **)** |virtual| |const| |
|
||||
+---------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
|
||||
.. rst-class:: classref-section-separator
|
||||
|
||||
----
|
||||
|
||||
.. rst-class:: classref-descriptions-group
|
||||
|
||||
Enumerations
|
||||
------------
|
||||
|
||||
.. _enum_ResourceFormatLoader_CacheMode:
|
||||
|
||||
.. _class_ResourceFormatLoader_constant_CACHE_MODE_IGNORE:
|
||||
|
||||
.. _class_ResourceFormatLoader_constant_CACHE_MODE_REUSE:
|
||||
|
||||
.. _class_ResourceFormatLoader_constant_CACHE_MODE_REPLACE:
|
||||
.. rst-class:: classref-enumeration
|
||||
|
||||
enum **CacheMode**:
|
||||
|
||||
- **CACHE_MODE_IGNORE** = **0**
|
||||
.. _class_ResourceFormatLoader_constant_CACHE_MODE_IGNORE:
|
||||
|
||||
- **CACHE_MODE_REUSE** = **1**
|
||||
.. rst-class:: classref-enumeration-constant
|
||||
|
||||
- **CACHE_MODE_REPLACE** = **2**
|
||||
:ref:`CacheMode<enum_ResourceFormatLoader_CacheMode>` **CACHE_MODE_IGNORE** = ``0``
|
||||
|
||||
|
||||
|
||||
.. _class_ResourceFormatLoader_constant_CACHE_MODE_REUSE:
|
||||
|
||||
.. rst-class:: classref-enumeration-constant
|
||||
|
||||
:ref:`CacheMode<enum_ResourceFormatLoader_CacheMode>` **CACHE_MODE_REUSE** = ``1``
|
||||
|
||||
|
||||
|
||||
.. _class_ResourceFormatLoader_constant_CACHE_MODE_REPLACE:
|
||||
|
||||
.. rst-class:: classref-enumeration-constant
|
||||
|
||||
:ref:`CacheMode<enum_ResourceFormatLoader_CacheMode>` **CACHE_MODE_REPLACE** = ``2``
|
||||
|
||||
|
||||
|
||||
.. rst-class:: classref-section-separator
|
||||
|
||||
----
|
||||
|
||||
.. rst-class:: classref-descriptions-group
|
||||
|
||||
Method Descriptions
|
||||
-------------------
|
||||
|
||||
.. _class_ResourceFormatLoader_method__exists:
|
||||
|
||||
- :ref:`bool<class_bool>` **_exists** **(** :ref:`String<class_String>` path **)** |virtual| |const|
|
||||
.. rst-class:: classref-method
|
||||
|
||||
:ref:`bool<class_bool>` **_exists** **(** :ref:`String<class_String>` path **)** |virtual| |const|
|
||||
|
||||
.. container:: contribute
|
||||
|
||||
There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
----
|
||||
|
||||
.. _class_ResourceFormatLoader_method__get_classes_used:
|
||||
|
||||
- :ref:`PackedStringArray<class_PackedStringArray>` **_get_classes_used** **(** :ref:`String<class_String>` path **)** |virtual| |const|
|
||||
.. rst-class:: classref-method
|
||||
|
||||
:ref:`PackedStringArray<class_PackedStringArray>` **_get_classes_used** **(** :ref:`String<class_String>` path **)** |virtual| |const|
|
||||
|
||||
.. container:: contribute
|
||||
|
||||
There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
----
|
||||
|
||||
.. _class_ResourceFormatLoader_method__get_dependencies:
|
||||
|
||||
- :ref:`PackedStringArray<class_PackedStringArray>` **_get_dependencies** **(** :ref:`String<class_String>` path, :ref:`bool<class_bool>` add_types **)** |virtual| |const|
|
||||
.. rst-class:: classref-method
|
||||
|
||||
:ref:`PackedStringArray<class_PackedStringArray>` **_get_dependencies** **(** :ref:`String<class_String>` path, :ref:`bool<class_bool>` add_types **)** |virtual| |const|
|
||||
|
||||
If implemented, gets the dependencies of a given resource. If ``add_types`` is ``true``, paths should be appended ``::TypeName``, where ``TypeName`` is the class name of the dependency.
|
||||
|
||||
\ **Note:** Custom resource types defined by scripts aren't known by the :ref:`ClassDB<class_ClassDB>`, so you might just return ``"Resource"`` for them.
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
----
|
||||
|
||||
.. _class_ResourceFormatLoader_method__get_recognized_extensions:
|
||||
|
||||
- :ref:`PackedStringArray<class_PackedStringArray>` **_get_recognized_extensions** **(** **)** |virtual| |const|
|
||||
.. rst-class:: classref-method
|
||||
|
||||
:ref:`PackedStringArray<class_PackedStringArray>` **_get_recognized_extensions** **(** **)** |virtual| |const|
|
||||
|
||||
Gets the list of extensions for files this loader is able to read.
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
----
|
||||
|
||||
.. _class_ResourceFormatLoader_method__get_resource_type:
|
||||
|
||||
- :ref:`String<class_String>` **_get_resource_type** **(** :ref:`String<class_String>` path **)** |virtual| |const|
|
||||
.. rst-class:: classref-method
|
||||
|
||||
:ref:`String<class_String>` **_get_resource_type** **(** :ref:`String<class_String>` path **)** |virtual| |const|
|
||||
|
||||
Gets the class name of the resource associated with the given path. If the loader cannot handle it, it should return ``""``.
|
||||
|
||||
\ **Note:** Custom resource types defined by scripts aren't known by the :ref:`ClassDB<class_ClassDB>`, so you might just return ``"Resource"`` for them.
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
----
|
||||
|
||||
.. _class_ResourceFormatLoader_method__get_resource_uid:
|
||||
|
||||
- :ref:`int<class_int>` **_get_resource_uid** **(** :ref:`String<class_String>` path **)** |virtual| |const|
|
||||
.. rst-class:: classref-method
|
||||
|
||||
:ref:`int<class_int>` **_get_resource_uid** **(** :ref:`String<class_String>` path **)** |virtual| |const|
|
||||
|
||||
.. container:: contribute
|
||||
|
||||
There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
----
|
||||
|
||||
.. _class_ResourceFormatLoader_method__handles_type:
|
||||
|
||||
- :ref:`bool<class_bool>` **_handles_type** **(** :ref:`StringName<class_StringName>` type **)** |virtual| |const|
|
||||
.. rst-class:: classref-method
|
||||
|
||||
:ref:`bool<class_bool>` **_handles_type** **(** :ref:`StringName<class_StringName>` type **)** |virtual| |const|
|
||||
|
||||
Tells which resource class this loader can load.
|
||||
|
||||
\ **Note:** Custom resource types defined by scripts aren't known by the :ref:`ClassDB<class_ClassDB>`, so you might just handle ``"Resource"`` for them.
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
----
|
||||
|
||||
.. _class_ResourceFormatLoader_method__load:
|
||||
|
||||
- :ref:`Variant<class_Variant>` **_load** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` original_path, :ref:`bool<class_bool>` use_sub_threads, :ref:`int<class_int>` cache_mode **)** |virtual| |const|
|
||||
.. rst-class:: classref-method
|
||||
|
||||
:ref:`Variant<class_Variant>` **_load** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` original_path, :ref:`bool<class_bool>` use_sub_threads, :ref:`int<class_int>` cache_mode **)** |virtual| |const|
|
||||
|
||||
Loads a resource when the engine finds this loader to be compatible. If the loaded resource is the result of an import, ``original_path`` will target the source file. Returns a :ref:`Resource<class_Resource>` object on success, or an :ref:`Error<enum_@GlobalScope_Error>` constant in case of failure.
|
||||
|
||||
The ``cache_mode`` property defines whether and how the cache should be used or updated when loading the resource. See :ref:`CacheMode<enum_ResourceFormatLoader_CacheMode>` for details.
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
----
|
||||
|
||||
.. _class_ResourceFormatLoader_method__recognize_path:
|
||||
|
||||
- :ref:`bool<class_bool>` **_recognize_path** **(** :ref:`String<class_String>` path, :ref:`StringName<class_StringName>` type **)** |virtual| |const|
|
||||
.. rst-class:: classref-method
|
||||
|
||||
:ref:`bool<class_bool>` **_recognize_path** **(** :ref:`String<class_String>` path, :ref:`StringName<class_StringName>` type **)** |virtual| |const|
|
||||
|
||||
Tells whether or not this loader should load a resource from its resource path for a given type.
|
||||
|
||||
If it is not implemented, the default behavior returns whether the path's extension is within the ones provided by :ref:`_get_recognized_extensions<class_ResourceFormatLoader_method__get_recognized_extensions>`, and if the type is within the ones provided by :ref:`_get_resource_type<class_ResourceFormatLoader_method__get_resource_type>`.
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
----
|
||||
|
||||
.. _class_ResourceFormatLoader_method__rename_dependencies:
|
||||
|
||||
- :ref:`int<class_int>` **_rename_dependencies** **(** :ref:`String<class_String>` path, :ref:`Dictionary<class_Dictionary>` renames **)** |virtual| |const|
|
||||
.. rst-class:: classref-method
|
||||
|
||||
:ref:`int<class_int>` **_rename_dependencies** **(** :ref:`String<class_String>` path, :ref:`Dictionary<class_Dictionary>` renames **)** |virtual| |const|
|
||||
|
||||
If implemented, renames dependencies within the given resource and saves it. ``renames`` is a dictionary ``{ String => String }`` mapping old dependency paths to new paths.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user