class_editorscript.rst 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_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. \ **Note:** Extending scripts need to have ``tool`` mode enabled.
  16. \ **Example script:**\
  17. .. tabs::
  18. .. code-tab:: gdscript
  19. @tool
  20. extends EditorScript
  21. func _run():
  22. print("Hello from the Godot Editor!")
  23. .. code-tab:: csharp
  24. using Godot;
  25. using System;
  26. [Tool]
  27. public 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_method__run>` **(** **)** |virtual| |
  43. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
  44. | void | :ref:`add_root_node<class_EditorScript_method_add_root_node>` **(** :ref:`Node<class_Node>` node **)** |
  45. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
  46. | :ref:`EditorInterface<class_EditorInterface>` | :ref:`get_editor_interface<class_EditorScript_method_get_editor_interface>` **(** **)** |
  47. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
  48. | :ref:`Node<class_Node>` | :ref:`get_scene<class_EditorScript_method_get_scene>` **(** **)** |
  49. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
  50. .. rst-class:: classref-section-separator
  51. ----
  52. .. rst-class:: classref-descriptions-group
  53. Method Descriptions
  54. -------------------
  55. .. _class_EditorScript_method__run:
  56. .. rst-class:: classref-method
  57. void **_run** **(** **)** |virtual|
  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** **(** :ref:`Node<class_Node>` node **)**
  64. Adds ``node`` as a child of the root node in the editor context.
  65. \ **Warning:** The implementation of this method is currently disabled.
  66. .. rst-class:: classref-item-separator
  67. ----
  68. .. _class_EditorScript_method_get_editor_interface:
  69. .. rst-class:: classref-method
  70. :ref:`EditorInterface<class_EditorInterface>` **get_editor_interface** **(** **)**
  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** **(** **)**
  77. Returns the Editor's currently active scene.
  78. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  79. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  80. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  81. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  82. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  83. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`