class_editorplugin.rst 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_EditorPlugin:
  4. EditorPlugin
  5. ============
  6. **Inherits:** :ref:`Node<class_node>` **<** :ref:`Object<class_object>`
  7. **Category:** Core
  8. Brief Description
  9. -----------------
  10. Used by the editor to extend its functionality.
  11. Member Functions
  12. ----------------
  13. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | :ref:`ToolButton<class_toolbutton>` | :ref:`add_control_to_bottom_panel<class_EditorPlugin_add_control_to_bottom_panel>` **(** :ref:`Control<class_control>` control, :ref:`String<class_string>` title **)** |
  15. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | void | :ref:`add_control_to_container<class_EditorPlugin_add_control_to_container>` **(** :ref:`int<class_int>` container, :ref:`Control<class_control>` control **)** |
  17. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | void | :ref:`add_control_to_dock<class_EditorPlugin_add_control_to_dock>` **(** :ref:`int<class_int>` slot, :ref:`Control<class_control>` control **)** |
  19. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | void | :ref:`add_custom_type<class_EditorPlugin_add_custom_type>` **(** :ref:`String<class_string>` type, :ref:`String<class_string>` base, :ref:`Script<class_script>` script, :ref:`Texture<class_texture>` icon **)** |
  21. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | void | :ref:`add_export_plugin<class_EditorPlugin_add_export_plugin>` **(** :ref:`EditorExportPlugin<class_editorexportplugin>` plugin **)** |
  23. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | void | :ref:`add_import_plugin<class_EditorPlugin_add_import_plugin>` **(** :ref:`EditorImportPlugin<class_editorimportplugin>` plugin **)** |
  25. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | void | :ref:`apply_changes<class_EditorPlugin_apply_changes>` **(** **)** virtual |
  27. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | void | :ref:`clear<class_EditorPlugin_clear>` **(** **)** virtual |
  29. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`EditorSpatialGizmo<class_editorspatialgizmo>` | :ref:`create_spatial_gizmo<class_EditorPlugin_create_spatial_gizmo>` **(** :ref:`Spatial<class_spatial>` for_spatial **)** virtual |
  31. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | void | :ref:`edit<class_EditorPlugin_edit>` **(** :ref:`Object<class_object>` object **)** virtual |
  33. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | void | :ref:`edit_resource<class_EditorPlugin_edit_resource>` **(** :ref:`Object<class_object>` arg0 **)** |
  35. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`bool<class_bool>` | :ref:`forward_input_event<class_EditorPlugin_forward_input_event>` **(** :ref:`InputEvent<class_inputevent>` event **)** virtual |
  37. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`bool<class_bool>` | :ref:`forward_spatial_input_event<class_EditorPlugin_forward_spatial_input_event>` **(** :ref:`Camera<class_camera>` camera, :ref:`InputEvent<class_inputevent>` event **)** virtual |
  39. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Control<class_control>` | :ref:`get_base_control<class_EditorPlugin_get_base_control>` **(** **)** |
  41. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`StringArray<class_stringarray>` | :ref:`get_breakpoints<class_EditorPlugin_get_breakpoints>` **(** **)** virtual |
  43. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`EditorSettings<class_editorsettings>` | :ref:`get_editor_settings<class_EditorPlugin_get_editor_settings>` **(** **)** |
  45. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Control<class_control>` | :ref:`get_editor_viewport<class_EditorPlugin_get_editor_viewport>` **(** **)** |
  47. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`String<class_string>` | :ref:`get_name<class_EditorPlugin_get_name>` **(** **)** virtual |
  49. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`EditorSelection<class_editorselection>` | :ref:`get_selection<class_EditorPlugin_get_selection>` **(** **)** |
  51. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Dictionary<class_dictionary>` | :ref:`get_state<class_EditorPlugin_get_state>` **(** **)** virtual |
  53. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`UndoRedo<class_undoredo>` | :ref:`get_undo_redo<class_EditorPlugin_get_undo_redo>` **(** **)** |
  55. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | void | :ref:`get_window_layout<class_EditorPlugin_get_window_layout>` **(** :ref:`ConfigFile<class_configfile>` layout **)** virtual |
  57. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`bool<class_bool>` | :ref:`handles<class_EditorPlugin_handles>` **(** :ref:`Object<class_object>` object **)** virtual |
  59. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`bool<class_bool>` | :ref:`has_main_screen<class_EditorPlugin_has_main_screen>` **(** **)** virtual |
  61. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`make_visible<class_EditorPlugin_make_visible>` **(** :ref:`bool<class_bool>` visible **)** virtual |
  63. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`queue_save_layout<class_EditorPlugin_queue_save_layout>` **(** **)** const |
  65. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`remove_control_from_bottom_panel<class_EditorPlugin_remove_control_from_bottom_panel>` **(** :ref:`Control<class_control>` control **)** |
  67. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | void | :ref:`remove_control_from_docks<class_EditorPlugin_remove_control_from_docks>` **(** :ref:`Control<class_control>` control **)** |
  69. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | void | :ref:`remove_custom_type<class_EditorPlugin_remove_custom_type>` **(** :ref:`String<class_string>` type **)** |
  71. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | void | :ref:`remove_export_plugin<class_EditorPlugin_remove_export_plugin>` **(** :ref:`EditorExportPlugin<class_editorexportplugin>` plugin **)** |
  73. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | void | :ref:`remove_import_plugin<class_EditorPlugin_remove_import_plugin>` **(** :ref:`EditorImportPlugin<class_editorimportplugin>` plugin **)** |
  75. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | void | :ref:`save_external_data<class_EditorPlugin_save_external_data>` **(** **)** virtual |
  77. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | void | :ref:`set_state<class_EditorPlugin_set_state>` **(** :ref:`Dictionary<class_dictionary>` state **)** virtual |
  79. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`set_window_layout<class_EditorPlugin_set_window_layout>` **(** :ref:`ConfigFile<class_configfile>` layout **)** virtual |
  81. +------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. Numeric Constants
  83. -----------------
  84. - **CONTAINER_TOOLBAR** = **0**
  85. - **CONTAINER_SPATIAL_EDITOR_MENU** = **1**
  86. - **CONTAINER_SPATIAL_EDITOR_SIDE** = **2**
  87. - **CONTAINER_SPATIAL_EDITOR_BOTTOM** = **3**
  88. - **CONTAINER_CANVAS_EDITOR_MENU** = **4**
  89. - **CONTAINER_CANVAS_EDITOR_SIDE** = **5**
  90. - **CONTAINER_PROPERTY_EDITOR_BOTTOM** = **7**
  91. - **DOCK_SLOT_LEFT_UL** = **0**
  92. - **DOCK_SLOT_LEFT_BL** = **1**
  93. - **DOCK_SLOT_LEFT_UR** = **2**
  94. - **DOCK_SLOT_LEFT_BR** = **3**
  95. - **DOCK_SLOT_RIGHT_UL** = **4**
  96. - **DOCK_SLOT_RIGHT_BL** = **5**
  97. - **DOCK_SLOT_RIGHT_UR** = **6**
  98. - **DOCK_SLOT_RIGHT_BR** = **7**
  99. - **DOCK_SLOT_MAX** = **8**
  100. Description
  101. -----------
  102. Plugins are used by the editor to extend functionality. The most common types of plugins are those which edit a given node or resource type, import plugins and export plugins.
  103. Member Function Description
  104. ---------------------------
  105. .. _class_EditorPlugin_add_control_to_bottom_panel:
  106. - :ref:`ToolButton<class_toolbutton>` **add_control_to_bottom_panel** **(** :ref:`Control<class_control>` control, :ref:`String<class_string>` title **)**
  107. Add a control to the bottom panel (together with Output, Debug, Animation, etc). Returns a reference to the button added. It's up to you to hide/show the button when needed. If your plugin is being removed, also make sure to remove your control by calling :ref:`remove_control_from_bottom_panel<class_EditorPlugin_remove_control_from_bottom_panel>`.
  108. .. _class_EditorPlugin_add_control_to_container:
  109. - void **add_control_to_container** **(** :ref:`int<class_int>` container, :ref:`Control<class_control>` control **)**
  110. Add a custom control to a container (see CONTAINER\_\* enum). There are many locations where custom controls can be added in the editor UI.
  111. Please remember that you have to manage the visibility of your custom controls yourself (and likely hide it after adding it).
  112. If your plugin is being removed, also make sure to remove your custom controls too.
  113. .. _class_EditorPlugin_add_control_to_dock:
  114. - void **add_control_to_dock** **(** :ref:`int<class_int>` slot, :ref:`Control<class_control>` control **)**
  115. Add the control to a specific dock slot (see DOCK\_\* enum for options).
  116. If the dock is repositioned and as long as the plugin is active, the editor will save the dock position on further sessions.
  117. If your plugin is being removed, also make sure to remove your control by calling :ref:`remove_control_from_docks<class_EditorPlugin_remove_control_from_docks>`.
  118. .. _class_EditorPlugin_add_custom_type:
  119. - void **add_custom_type** **(** :ref:`String<class_string>` type, :ref:`String<class_string>` base, :ref:`Script<class_script>` script, :ref:`Texture<class_texture>` icon **)**
  120. Add a custom type, which will appear in the list of nodes or resources. An icon can be optionally passed.
  121. When given node or resource is selected, the base type will be instanced (ie, "Spatial", "Control", "Resource"), then the script will be loaded and set to this object.
  122. You can use the :ref:`EditorPlugin.handles<class_EditorPlugin_handles>` to check if your custom object is being edited by checking the script or using 'extends' keyword.
  123. During run-time, this will be a simple object with a script so this function does not need to be called then.
  124. .. _class_EditorPlugin_add_export_plugin:
  125. - void **add_export_plugin** **(** :ref:`EditorExportPlugin<class_editorexportplugin>` plugin **)**
  126. Add an export plugin. Plugins of this kind can change files being exported. On exit don't forget to call :ref:`remove_export_plugin<class_EditorPlugin_remove_export_plugin>`.
  127. .. _class_EditorPlugin_add_import_plugin:
  128. - void **add_import_plugin** **(** :ref:`EditorImportPlugin<class_editorimportplugin>` plugin **)**
  129. Add an import plugin. These plugins manage importing external content (from outside the project) into formats the engine can understand.
  130. On exit, don't forget to remove the plugin by calling :ref:`remove_import_plugin<class_EditorPlugin_remove_import_plugin>`
  131. .. _class_EditorPlugin_apply_changes:
  132. - void **apply_changes** **(** **)** virtual
  133. This method is called when the editor is about to save the project, switch to another tab, etc. It asks the plugin to apply any pending state changes to ensure consistency.
  134. This is used, for example, in shader editors to let the plugin know that it must apply the shader code being written by the user to the object.
  135. .. _class_EditorPlugin_clear:
  136. - void **clear** **(** **)** virtual
  137. Clear all the state and reset the object being edited to zero. This ensures your plugin does not keep editing a currently existing node, or a node from the wrong scene.
  138. .. _class_EditorPlugin_create_spatial_gizmo:
  139. - :ref:`EditorSpatialGizmo<class_editorspatialgizmo>` **create_spatial_gizmo** **(** :ref:`Spatial<class_spatial>` for_spatial **)** virtual
  140. This is used for plugins that create gizmos used by the spatial editor. Just check that the node passed in the "for_spatial" argument matches your plugin.
  141. .. _class_EditorPlugin_edit:
  142. - void **edit** **(** :ref:`Object<class_object>` object **)** virtual
  143. This function is used for plugins that edit specific object types (nodes or resources). It requests the editor to edit the given object.
  144. .. _class_EditorPlugin_edit_resource:
  145. - void **edit_resource** **(** :ref:`Object<class_object>` arg0 **)**
  146. Tells the editor to handle the edit of the given resource. For example, if you pass a script as argument, the editor will open the script editor.
  147. .. _class_EditorPlugin_forward_input_event:
  148. - :ref:`bool<class_bool>` **forward_input_event** **(** :ref:`InputEvent<class_inputevent>` event **)** virtual
  149. This is a low level function for plugins that edit a given object type derived from CanvasItem to capture the input in the 2D editor viewport. The function is only being called if your object is being edited.
  150. Return true if you want to capture the input, otherwise false.
  151. .. _class_EditorPlugin_forward_spatial_input_event:
  152. - :ref:`bool<class_bool>` **forward_spatial_input_event** **(** :ref:`Camera<class_camera>` camera, :ref:`InputEvent<class_inputevent>` event **)** virtual
  153. This is a low level function for plugins that edit a given objet type derived from Spatial to capture the input of the viewport. The function is only being called if your object is being edited.
  154. By using the :ref:`InputEvent<class_inputevent>` and the :ref:`Camera<class_camera>` arguments it's pretty easy to do raycasts into space using Camera functions.
  155. Return true if you want to capture the input, otherwise false.
  156. .. _class_EditorPlugin_get_base_control:
  157. - :ref:`Control<class_control>` **get_base_control** **(** **)**
  158. Get a base control where it's safe to place dialogs. Many plugins open dialogs and they need a control as a base to make sure they use the editor icons and theme.
  159. .. _class_EditorPlugin_get_breakpoints:
  160. - :ref:`StringArray<class_stringarray>` **get_breakpoints** **(** **)** virtual
  161. This is for editors that edit script based objects. You can return a list of breakpoints in the format (script:line), for example: res://path_to_script.gd:25
  162. .. _class_EditorPlugin_get_editor_settings:
  163. - :ref:`EditorSettings<class_editorsettings>` **get_editor_settings** **(** **)**
  164. Get the general settings for the editor (the same window that appears in the Settings menu).
  165. .. _class_EditorPlugin_get_editor_viewport:
  166. - :ref:`Control<class_control>` **get_editor_viewport** **(** **)**
  167. Get the main editor control. Use this as a parent for main screens.
  168. .. _class_EditorPlugin_get_name:
  169. - :ref:`String<class_string>` **get_name** **(** **)** virtual
  170. Get the name of the editor plugin. For main scren plugins this is what will appear in the selector (which by default is 2D, 3D, Script).
  171. .. _class_EditorPlugin_get_selection:
  172. - :ref:`EditorSelection<class_editorselection>` **get_selection** **(** **)**
  173. Get the object that handles the selection of nodes in the Scene Tree editor.
  174. .. _class_EditorPlugin_get_state:
  175. - :ref:`Dictionary<class_dictionary>` **get_state** **(** **)** virtual
  176. Get the state of your plugin editor. This is used when saving the scene (so state is kept when opening it again) and for switching tabs (so state can be restored when the tab returns).
  177. .. _class_EditorPlugin_get_undo_redo:
  178. - :ref:`UndoRedo<class_undoredo>` **get_undo_redo** **(** **)**
  179. Get the undo/redo object. Most actions in the editor can be undoable, so use this object to make sure this happens when it's worth it.
  180. .. _class_EditorPlugin_get_window_layout:
  181. - void **get_window_layout** **(** :ref:`ConfigFile<class_configfile>` layout **)** virtual
  182. Get the GUI layout of the plugin. This is used to save the project's editor layout when the :ref:`EditorPlugin.queue_save_layout<class_EditorPlugin_queue_save_layout>` is called or the editor layout was changed(For example changing the position of a dock).
  183. .. _class_EditorPlugin_handles:
  184. - :ref:`bool<class_bool>` **handles** **(** :ref:`Object<class_object>` object **)** virtual
  185. Implement this function if your plugin edits a specific type of object (Resource or Node). If you return true, then you will get the functions :ref:`EditorPlugin.edit<class_EditorPlugin_edit>` and :ref:`EditorPlugin.make_visible<class_EditorPlugin_make_visible>` called when the editor requests them.
  186. .. _class_EditorPlugin_has_main_screen:
  187. - :ref:`bool<class_bool>` **has_main_screen** **(** **)** virtual
  188. Return true if this is a main screen editor plugin (it goes in the main screen selector together with 2D, 3D, Script).
  189. .. _class_EditorPlugin_make_visible:
  190. - void **make_visible** **(** :ref:`bool<class_bool>` visible **)** virtual
  191. This function will be called when the editor is requested to become visible. It is used for plugins that edit a specific object type.
  192. Remember that you have to manage the visibility of all your editor controls manually.
  193. .. _class_EditorPlugin_queue_save_layout:
  194. - void **queue_save_layout** **(** **)** const
  195. Queue save the project's editor layout.
  196. .. _class_EditorPlugin_remove_control_from_bottom_panel:
  197. - void **remove_control_from_bottom_panel** **(** :ref:`Control<class_control>` control **)**
  198. Remove the control from the bottom panel. Don't forget to call this if you added one, so the editor can remove it cleanly.
  199. .. _class_EditorPlugin_remove_control_from_docks:
  200. - void **remove_control_from_docks** **(** :ref:`Control<class_control>` control **)**
  201. Remove the control from the dock. Don't forget to call this if you added one, so the editor can save the layout and remove it cleanly.
  202. .. _class_EditorPlugin_remove_custom_type:
  203. - void **remove_custom_type** **(** :ref:`String<class_string>` type **)**
  204. Remove a custom type added by :ref:`EditorPlugin.add_custom_type<class_EditorPlugin_add_custom_type>`
  205. .. _class_EditorPlugin_remove_export_plugin:
  206. - void **remove_export_plugin** **(** :ref:`EditorExportPlugin<class_editorexportplugin>` plugin **)**
  207. Remove the export plugin, don't forget to call this on exit.
  208. .. _class_EditorPlugin_remove_import_plugin:
  209. - void **remove_import_plugin** **(** :ref:`EditorImportPlugin<class_editorimportplugin>` plugin **)**
  210. Remove the import plugin, don't forget to call this on exit.
  211. .. _class_EditorPlugin_save_external_data:
  212. - void **save_external_data** **(** **)** virtual
  213. This method is called after the editor saves the project or when it's closed. It asks the plugin to save edited external scenes/resources.
  214. .. _class_EditorPlugin_set_state:
  215. - void **set_state** **(** :ref:`Dictionary<class_dictionary>` state **)** virtual
  216. Restore the state saved by :ref:`EditorPlugin.get_state<class_EditorPlugin_get_state>`.
  217. .. _class_EditorPlugin_set_window_layout:
  218. - void **set_window_layout** **(** :ref:`ConfigFile<class_configfile>` layout **)** virtual
  219. Restore the plugin GUI layout saved by :ref:`EditorPlugin.get_window_layout<class_EditorPlugin_get_window_layout>`.