class_editorimportplugin.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the EditorImportPlugin.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_EditorImportPlugin:
  6. EditorImportPlugin
  7. ==================
  8. **Inherits:** :ref:`ResourceImporter<class_ResourceImporter>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. Registers a custom resource importer in the editor. Use the class to parse any file and import it as a new resource type.
  10. Description
  11. -----------
  12. EditorImportPlugins 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. Register your :ref:`EditorPlugin<class_EditorPlugin>` with :ref:`EditorPlugin.add_import_plugin<class_EditorPlugin_method_add_import_plugin>`.
  13. 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.
  14. Below is an example EditorImportPlugin that imports a :ref:`Mesh<class_Mesh>` from a file with the extension ".special" or ".spec":
  15. ::
  16. tool
  17. extends EditorImportPlugin
  18. func get_importer_name():
  19. return "my.special.plugin"
  20. func get_visible_name():
  21. return "Special Mesh Importer"
  22. func get_recognized_extensions():
  23. return ["special", "spec"]
  24. func get_save_extension():
  25. return "mesh"
  26. func get_resource_type():
  27. return "Mesh"
  28. func get_preset_count():
  29. return 1
  30. func get_preset_name(i):
  31. return "Default"
  32. func get_import_options(i):
  33. return [{"name": "my_option", "default_value": false}]
  34. func import(source_file, save_path, options, platform_variants, gen_files):
  35. var file = File.new()
  36. if file.open(source_file, File.READ) != OK:
  37. return FAILED
  38. var mesh = Mesh.new()
  39. # Fill the Mesh with data read in "file", left as an exercise to the reader
  40. var filename = save_path + "." + get_save_extension()
  41. ResourceSaver.save(filename, mesh)
  42. return OK
  43. Tutorials
  44. ---------
  45. - :doc:`../tutorials/plugins/editor/import_plugins`
  46. Methods
  47. -------
  48. +-----------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Array<class_Array>` | :ref:`get_import_options<class_EditorImportPlugin_method_get_import_options>` **(** :ref:`int<class_int>` preset **)** virtual |
  50. +-----------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`int<class_int>` | :ref:`get_import_order<class_EditorImportPlugin_method_get_import_order>` **(** **)** virtual |
  52. +-----------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`String<class_String>` | :ref:`get_importer_name<class_EditorImportPlugin_method_get_importer_name>` **(** **)** virtual |
  54. +-----------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :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 |
  56. +-----------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`int<class_int>` | :ref:`get_preset_count<class_EditorImportPlugin_method_get_preset_count>` **(** **)** virtual |
  58. +-----------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`String<class_String>` | :ref:`get_preset_name<class_EditorImportPlugin_method_get_preset_name>` **(** :ref:`int<class_int>` preset **)** virtual |
  60. +-----------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`float<class_float>` | :ref:`get_priority<class_EditorImportPlugin_method_get_priority>` **(** **)** virtual |
  62. +-----------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`Array<class_Array>` | :ref:`get_recognized_extensions<class_EditorImportPlugin_method_get_recognized_extensions>` **(** **)** virtual |
  64. +-----------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`String<class_String>` | :ref:`get_resource_type<class_EditorImportPlugin_method_get_resource_type>` **(** **)** virtual |
  66. +-----------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`String<class_String>` | :ref:`get_save_extension<class_EditorImportPlugin_method_get_save_extension>` **(** **)** virtual |
  68. +-----------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`String<class_String>` | :ref:`get_visible_name<class_EditorImportPlugin_method_get_visible_name>` **(** **)** virtual |
  70. +-----------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :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 |
  72. +-----------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. Method Descriptions
  74. -------------------
  75. .. _class_EditorImportPlugin_method_get_import_options:
  76. - :ref:`Array<class_Array>` **get_import_options** **(** :ref:`int<class_int>` preset **)** virtual
  77. 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).
  78. ----
  79. .. _class_EditorImportPlugin_method_get_import_order:
  80. - :ref:`int<class_int>` **get_import_order** **(** **)** virtual
  81. Gets the order of this importer to be run when importing resources. Higher values will be called later. Use this to ensure the importer runs after the dependencies are already imported.
  82. ----
  83. .. _class_EditorImportPlugin_method_get_importer_name:
  84. - :ref:`String<class_String>` **get_importer_name** **(** **)** virtual
  85. Gets the unique name of the importer.
  86. ----
  87. .. _class_EditorImportPlugin_method_get_option_visibility:
  88. - :ref:`bool<class_bool>` **get_option_visibility** **(** :ref:`String<class_String>` option, :ref:`Dictionary<class_Dictionary>` options **)** virtual
  89. ----
  90. .. _class_EditorImportPlugin_method_get_preset_count:
  91. - :ref:`int<class_int>` **get_preset_count** **(** **)** virtual
  92. 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.
  93. ----
  94. .. _class_EditorImportPlugin_method_get_preset_name:
  95. - :ref:`String<class_String>` **get_preset_name** **(** :ref:`int<class_int>` preset **)** virtual
  96. Gets the name of the options preset at this index.
  97. ----
  98. .. _class_EditorImportPlugin_method_get_priority:
  99. - :ref:`float<class_float>` **get_priority** **(** **)** virtual
  100. Gets the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. The default priority is ``1.0``.
  101. ----
  102. .. _class_EditorImportPlugin_method_get_recognized_extensions:
  103. - :ref:`Array<class_Array>` **get_recognized_extensions** **(** **)** virtual
  104. Gets the list of file extensions to associate with this loader (case-insensitive). e.g. ``["obj"]``.
  105. ----
  106. .. _class_EditorImportPlugin_method_get_resource_type:
  107. - :ref:`String<class_String>` **get_resource_type** **(** **)** virtual
  108. Gets the Godot resource type associated with this loader. e.g. ``"Mesh"`` or ``"Animation"``.
  109. ----
  110. .. _class_EditorImportPlugin_method_get_save_extension:
  111. - :ref:`String<class_String>` **get_save_extension** **(** **)** virtual
  112. Gets the extension used to save this resource in the ``.import`` directory.
  113. ----
  114. .. _class_EditorImportPlugin_method_get_visible_name:
  115. - :ref:`String<class_String>` **get_visible_name** **(** **)** virtual
  116. Gets the name to display in the import window.
  117. ----
  118. .. _class_EditorImportPlugin_method_import:
  119. - :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