class_editorresourceconversionplugin.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/4.2/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/EditorResourceConversionPlugin.xml.
  6. .. _class_EditorResourceConversionPlugin:
  7. EditorResourceConversionPlugin
  8. ==============================
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Plugin for adding custom converters from one resource format to another in the editor resource picker context menu; for example, converting a :ref:`StandardMaterial3D<class_StandardMaterial3D>` to a :ref:`ShaderMaterial<class_ShaderMaterial>`.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. **EditorResourceConversionPlugin** is invoked when the context menu is brought up for a resource in the editor inspector. Relevant conversion plugins will appear as menu options to convert the given resource to a target type.
  15. Below shows an example of a basic plugin that will convert an :ref:`ImageTexture<class_ImageTexture>` to a :ref:`PortableCompressedTexture2D<class_PortableCompressedTexture2D>`.
  16. .. tabs::
  17. .. code-tab:: gdscript
  18. extends EditorResourceConversionPlugin
  19. func _handles(resource: Resource):
  20. return resource is ImageTexture
  21. func _converts_to():
  22. return "PortableCompressedTexture2D"
  23. func _convert(itex: Resource):
  24. var ptex = PortableCompressedTexture2D.new()
  25. ptex.create_from_image(itex.get_image(), PortableCompressedTexture2D.COMPRESSION_MODE_LOSSLESS)
  26. return ptex
  27. To use an **EditorResourceConversionPlugin**, register it using the :ref:`EditorPlugin.add_resource_conversion_plugin<class_EditorPlugin_method_add_resource_conversion_plugin>` method first.
  28. .. rst-class:: classref-reftable-group
  29. Methods
  30. -------
  31. .. table::
  32. :widths: auto
  33. +---------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`Resource<class_Resource>` | :ref:`_convert<class_EditorResourceConversionPlugin_private_method__convert>` **(** :ref:`Resource<class_Resource>` resource **)** |virtual| |const| |
  35. +---------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`String<class_String>` | :ref:`_converts_to<class_EditorResourceConversionPlugin_private_method__converts_to>` **(** **)** |virtual| |const| |
  37. +---------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`bool<class_bool>` | :ref:`_handles<class_EditorResourceConversionPlugin_private_method__handles>` **(** :ref:`Resource<class_Resource>` resource **)** |virtual| |const| |
  39. +---------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. .. rst-class:: classref-section-separator
  41. ----
  42. .. rst-class:: classref-descriptions-group
  43. Method Descriptions
  44. -------------------
  45. .. _class_EditorResourceConversionPlugin_private_method__convert:
  46. .. rst-class:: classref-method
  47. :ref:`Resource<class_Resource>` **_convert** **(** :ref:`Resource<class_Resource>` resource **)** |virtual| |const|
  48. Takes an input :ref:`Resource<class_Resource>` and converts it to the type given in :ref:`_converts_to<class_EditorResourceConversionPlugin_private_method__converts_to>`. The returned :ref:`Resource<class_Resource>` is the result of the conversion, and the input :ref:`Resource<class_Resource>` remains unchanged.
  49. .. rst-class:: classref-item-separator
  50. ----
  51. .. _class_EditorResourceConversionPlugin_private_method__converts_to:
  52. .. rst-class:: classref-method
  53. :ref:`String<class_String>` **_converts_to** **(** **)** |virtual| |const|
  54. Returns the class name of the target type of :ref:`Resource<class_Resource>` that this plugin converts source resources to.
  55. .. rst-class:: classref-item-separator
  56. ----
  57. .. _class_EditorResourceConversionPlugin_private_method__handles:
  58. .. rst-class:: classref-method
  59. :ref:`bool<class_bool>` **_handles** **(** :ref:`Resource<class_Resource>` resource **)** |virtual| |const|
  60. Called to determine whether a particular :ref:`Resource<class_Resource>` can be converted to the target resource type by this plugin.
  61. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  62. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  63. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  64. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  65. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  66. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  67. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`