class_editorscript.rst 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/EditorScript.xml.
  6. .. _class_EditorScript:
  7. EditorScript
  8. ============
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Base script that can be used to add extension functions to the editor.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Scripts extending this class and implementing its :ref:`_run()<class_EditorScript_private_method__run>` method can be executed from the Script Editor's **File > Run** menu option (or by pressing :kbd:`Ctrl + Shift + X`) while the editor is running. This is useful for adding custom in-editor functionality to Godot. For more complex additions, consider using :ref:`EditorPlugin<class_EditorPlugin>`\ s instead.
  15. If a script extending this class also has a global class name, it will be included in the editor's command palette.
  16. \ **Note:** Extending scripts need to have ``tool`` mode enabled.
  17. \ **Example:** Running the following script prints "Hello from the Godot Editor!":
  18. .. tabs::
  19. .. code-tab:: gdscript
  20. @tool
  21. extends EditorScript
  22. func _run():
  23. print("Hello from the Godot Editor!")
  24. .. code-tab:: csharp
  25. using Godot;
  26. [Tool]
  27. public partial class HelloEditor : EditorScript
  28. {
  29. public override void _Run()
  30. {
  31. GD.Print("Hello from the Godot Editor!");
  32. }
  33. }
  34. \ **Note:** The script is run in the Editor context, which means the output is visible in the console window started with the Editor (stdout) instead of the usual Godot **Output** dock.
  35. \ **Note:** EditorScript is :ref:`RefCounted<class_RefCounted>`, meaning it is destroyed when nothing references it. This can cause errors during asynchronous operations if there are no references to the script.
  36. .. rst-class:: classref-reftable-group
  37. Methods
  38. -------
  39. .. table::
  40. :widths: auto
  41. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------+
  42. | |void| | :ref:`_run<class_EditorScript_private_method__run>`\ (\ ) |virtual| |required| |
  43. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------+
  44. | |void| | :ref:`add_root_node<class_EditorScript_method_add_root_node>`\ (\ node\: :ref:`Node<class_Node>`\ ) |
  45. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------+
  46. | :ref:`EditorInterface<class_EditorInterface>` | :ref:`get_editor_interface<class_EditorScript_method_get_editor_interface>`\ (\ ) |const| |
  47. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------+
  48. | :ref:`Node<class_Node>` | :ref:`get_scene<class_EditorScript_method_get_scene>`\ (\ ) |const| |
  49. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------+
  50. .. rst-class:: classref-section-separator
  51. ----
  52. .. rst-class:: classref-descriptions-group
  53. Method Descriptions
  54. -------------------
  55. .. _class_EditorScript_private_method__run:
  56. .. rst-class:: classref-method
  57. |void| **_run**\ (\ ) |virtual| |required| :ref:`🔗<class_EditorScript_private_method__run>`
  58. This method is executed by the Editor when **File > Run** is used.
  59. .. rst-class:: classref-item-separator
  60. ----
  61. .. _class_EditorScript_method_add_root_node:
  62. .. rst-class:: classref-method
  63. |void| **add_root_node**\ (\ node\: :ref:`Node<class_Node>`\ ) :ref:`🔗<class_EditorScript_method_add_root_node>`
  64. Makes ``node`` root of the currently opened scene. Only works if the scene is empty. If the ``node`` is a scene instance, an inheriting scene will be created.
  65. .. rst-class:: classref-item-separator
  66. ----
  67. .. _class_EditorScript_method_get_editor_interface:
  68. .. rst-class:: classref-method
  69. :ref:`EditorInterface<class_EditorInterface>` **get_editor_interface**\ (\ ) |const| :ref:`🔗<class_EditorScript_method_get_editor_interface>`
  70. **Deprecated:** :ref:`EditorInterface<class_EditorInterface>` is a global singleton and can be accessed directly by its name.
  71. Returns the :ref:`EditorInterface<class_EditorInterface>` singleton instance.
  72. .. rst-class:: classref-item-separator
  73. ----
  74. .. _class_EditorScript_method_get_scene:
  75. .. rst-class:: classref-method
  76. :ref:`Node<class_Node>` **get_scene**\ (\ ) |const| :ref:`🔗<class_EditorScript_method_get_scene>`
  77. Returns the edited (current) scene's root :ref:`Node<class_Node>`. Equivalent of :ref:`EditorInterface.get_edited_scene_root()<class_EditorInterface_method_get_edited_scene_root>`.
  78. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  79. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  80. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  81. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  82. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  83. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  84. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  85. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  86. .. |void| replace:: :abbr:`void (No return value.)`