class_editorimportplugin.rst 13 KB

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