class_editorimportplugin.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/EditorImportPlugin.xml.
  6. .. _class_EditorImportPlugin:
  7. EditorImportPlugin
  8. ==================
  9. **Inherits:** :ref:`ResourceImporter<class_ResourceImporter>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. Registers a custom resource importer in the editor. Use the class to parse any file and import it as a new resource type.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. **EditorImportPlugin**\ s provide a way to extend the editor's resource import functionality. Use them to import resources from custom files or to provide alternatives to the editor's existing importers.
  15. EditorImportPlugins work by associating with specific file extensions and a resource type. See :ref:`get_recognized_extensions<class_EditorImportPlugin_method_get_recognized_extensions>` and :ref:`get_resource_type<class_EditorImportPlugin_method_get_resource_type>`. They may optionally specify some import presets that affect the import process. EditorImportPlugins are responsible for creating the resources and saving them in the ``.import`` directory (see :ref:`ProjectSettings.application/config/use_hidden_project_data_directory<class_ProjectSettings_property_application/config/use_hidden_project_data_directory>`).
  16. Below is an example EditorImportPlugin that imports a :ref:`Mesh<class_Mesh>` from a file with the extension ".special" or ".spec":
  17. ::
  18. tool
  19. extends EditorImportPlugin
  20. func get_importer_name():
  21. return "my.special.plugin"
  22. func get_visible_name():
  23. return "Special Mesh"
  24. func get_recognized_extensions():
  25. return ["special", "spec"]
  26. func get_save_extension():
  27. return "mesh"
  28. func get_resource_type():
  29. return "Mesh"
  30. func get_preset_count():
  31. return 1
  32. func get_preset_name(i):
  33. return "Default"
  34. func get_import_options(i):
  35. return [{"name": "my_option", "default_value": false}]
  36. func import(source_file, save_path, options, platform_variants, gen_files):
  37. var file = File.new()
  38. if file.open(source_file, File.READ) != OK:
  39. return FAILED
  40. var mesh = Mesh.new()
  41. # Fill the Mesh with data read in "file", left as an exercise to the reader
  42. var filename = save_path + "." + get_save_extension()
  43. return ResourceSaver.save(filename, mesh)
  44. To use **EditorImportPlugin**, register it using the :ref:`EditorPlugin.add_import_plugin<class_EditorPlugin_method_add_import_plugin>` method first.
  45. .. rst-class:: classref-introduction-group
  46. Tutorials
  47. ---------
  48. - :doc:`../tutorials/plugins/editor/import_plugins`
  49. .. rst-class:: classref-reftable-group
  50. Methods
  51. -------
  52. .. table::
  53. :widths: auto
  54. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Array<class_Array>` | :ref:`get_import_options<class_EditorImportPlugin_method_get_import_options>` **(** :ref:`int<class_int>` preset **)** |virtual| |
  56. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`int<class_int>` | :ref:`get_import_order<class_EditorImportPlugin_method_get_import_order>` **(** **)** |virtual| |
  58. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`String<class_String>` | :ref:`get_importer_name<class_EditorImportPlugin_method_get_importer_name>` **(** **)** |virtual| |
  60. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`bool<class_bool>` | :ref:`get_option_visibility<class_EditorImportPlugin_method_get_option_visibility>` **(** :ref:`String<class_String>` option, :ref:`Dictionary<class_Dictionary>` options **)** |virtual| |
  62. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`int<class_int>` | :ref:`get_preset_count<class_EditorImportPlugin_method_get_preset_count>` **(** **)** |virtual| |
  64. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`String<class_String>` | :ref:`get_preset_name<class_EditorImportPlugin_method_get_preset_name>` **(** :ref:`int<class_int>` preset **)** |virtual| |
  66. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`float<class_float>` | :ref:`get_priority<class_EditorImportPlugin_method_get_priority>` **(** **)** |virtual| |
  68. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`Array<class_Array>` | :ref:`get_recognized_extensions<class_EditorImportPlugin_method_get_recognized_extensions>` **(** **)** |virtual| |
  70. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`String<class_String>` | :ref:`get_resource_type<class_EditorImportPlugin_method_get_resource_type>` **(** **)** |virtual| |
  72. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`String<class_String>` | :ref:`get_save_extension<class_EditorImportPlugin_method_get_save_extension>` **(** **)** |virtual| |
  74. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`String<class_String>` | :ref:`get_visible_name<class_EditorImportPlugin_method_get_visible_name>` **(** **)** |virtual| |
  76. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`int<class_int>` | :ref:`import<class_EditorImportPlugin_method_import>` **(** :ref:`String<class_String>` source_file, :ref:`String<class_String>` save_path, :ref:`Dictionary<class_Dictionary>` options, :ref:`Array<class_Array>` platform_variants, :ref:`Array<class_Array>` gen_files **)** |virtual| |
  78. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. .. rst-class:: classref-section-separator
  80. ----
  81. .. rst-class:: classref-descriptions-group
  82. Method Descriptions
  83. -------------------
  84. .. _class_EditorImportPlugin_method_get_import_options:
  85. .. rst-class:: classref-method
  86. :ref:`Array<class_Array>` **get_import_options** **(** :ref:`int<class_int>` preset **)** |virtual|
  87. Gets the options and default values for the preset at this index. Returns an Array of Dictionaries with the following keys: ``name``, ``default_value``, ``property_hint`` (optional), ``hint_string`` (optional), ``usage`` (optional).
  88. .. rst-class:: classref-item-separator
  89. ----
  90. .. _class_EditorImportPlugin_method_get_import_order:
  91. .. rst-class:: classref-method
  92. :ref:`int<class_int>` **get_import_order** **(** **)** |virtual|
  93. Gets the order of this importer to be run when importing resources. Importers with *lower* import orders will be called first, and higher values will be called later. Use this to ensure the importer runs after the dependencies are already imported. The default import order is ``0`` unless overridden by a specific importer. See :ref:`ImportOrder<enum_ResourceImporter_ImportOrder>` for some predefined values.
  94. .. rst-class:: classref-item-separator
  95. ----
  96. .. _class_EditorImportPlugin_method_get_importer_name:
  97. .. rst-class:: classref-method
  98. :ref:`String<class_String>` **get_importer_name** **(** **)** |virtual|
  99. Gets the unique name of the importer.
  100. .. rst-class:: classref-item-separator
  101. ----
  102. .. _class_EditorImportPlugin_method_get_option_visibility:
  103. .. rst-class:: classref-method
  104. :ref:`bool<class_bool>` **get_option_visibility** **(** :ref:`String<class_String>` option, :ref:`Dictionary<class_Dictionary>` options **)** |virtual|
  105. This method can be overridden to hide specific import options if conditions are met. This is mainly useful for hiding options that depend on others if one of them is disabled. For example:
  106. ::
  107. func get_option_visibility(option, options):
  108. # Only show the lossy quality setting if the compression mode is set to "Lossy".
  109. if option == "compress/lossy_quality" and options.has("compress/mode"):
  110. return int(options["compress/mode"]) == COMPRESS_LOSSY
  111. return true
  112. Return ``true`` to make all options always visible.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. _class_EditorImportPlugin_method_get_preset_count:
  116. .. rst-class:: classref-method
  117. :ref:`int<class_int>` **get_preset_count** **(** **)** |virtual|
  118. Gets the number of initial presets defined by the plugin. Use :ref:`get_import_options<class_EditorImportPlugin_method_get_import_options>` to get the default options for the preset and :ref:`get_preset_name<class_EditorImportPlugin_method_get_preset_name>` to get the name of the preset.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_EditorImportPlugin_method_get_preset_name:
  122. .. rst-class:: classref-method
  123. :ref:`String<class_String>` **get_preset_name** **(** :ref:`int<class_int>` preset **)** |virtual|
  124. Gets the name of the options preset at this index.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_EditorImportPlugin_method_get_priority:
  128. .. rst-class:: classref-method
  129. :ref:`float<class_float>` **get_priority** **(** **)** |virtual|
  130. Gets the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. The default priority is ``1.0``.
  131. .. rst-class:: classref-item-separator
  132. ----
  133. .. _class_EditorImportPlugin_method_get_recognized_extensions:
  134. .. rst-class:: classref-method
  135. :ref:`Array<class_Array>` **get_recognized_extensions** **(** **)** |virtual|
  136. Gets the list of file extensions to associate with this loader (case-insensitive). e.g. ``["obj"]``.
  137. .. rst-class:: classref-item-separator
  138. ----
  139. .. _class_EditorImportPlugin_method_get_resource_type:
  140. .. rst-class:: classref-method
  141. :ref:`String<class_String>` **get_resource_type** **(** **)** |virtual|
  142. Gets the Godot resource type associated with this loader. e.g. ``"Mesh"`` or ``"Animation"``.
  143. .. rst-class:: classref-item-separator
  144. ----
  145. .. _class_EditorImportPlugin_method_get_save_extension:
  146. .. rst-class:: classref-method
  147. :ref:`String<class_String>` **get_save_extension** **(** **)** |virtual|
  148. Gets the extension used to save this resource in the ``.import`` directory (see :ref:`ProjectSettings.application/config/use_hidden_project_data_directory<class_ProjectSettings_property_application/config/use_hidden_project_data_directory>`).
  149. .. rst-class:: classref-item-separator
  150. ----
  151. .. _class_EditorImportPlugin_method_get_visible_name:
  152. .. rst-class:: classref-method
  153. :ref:`String<class_String>` **get_visible_name** **(** **)** |virtual|
  154. Gets the name to display in the import window. You should choose this name as a continuation to "Import as", e.g. "Import as Special Mesh".
  155. .. rst-class:: classref-item-separator
  156. ----
  157. .. _class_EditorImportPlugin_method_import:
  158. .. rst-class:: classref-method
  159. :ref:`int<class_int>` **import** **(** :ref:`String<class_String>` source_file, :ref:`String<class_String>` save_path, :ref:`Dictionary<class_Dictionary>` options, :ref:`Array<class_Array>` platform_variants, :ref:`Array<class_Array>` gen_files **)** |virtual|
  160. Imports ``source_file`` into ``save_path`` with the import ``options`` specified. The ``platform_variants`` and ``gen_files`` arrays will be modified by this function.
  161. This method must be overridden to do the actual importing work. See this class' description for an example of overriding this method.
  162. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  163. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  164. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  165. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`