class_editorscript.rst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the EditorScript.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_EditorScript:
  6. EditorScript
  7. ============
  8. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  9. Base script that can be used to add extension functions to the editor.
  10. Description
  11. -----------
  12. 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.
  13. \ **Note:** Extending scripts need to have ``tool`` mode enabled.
  14. \ **Example script:**\
  15. .. tabs::
  16. .. code-tab:: gdscript
  17. tool
  18. extends EditorScript
  19. func _run():
  20. print("Hello from the Godot Editor!")
  21. .. code-tab:: csharp
  22. using Godot;
  23. using System;
  24. [Tool]
  25. public class HelloEditor : EditorScript
  26. {
  27. public override void _Run()
  28. {
  29. GD.Print("Hello from the Godot Editor!");
  30. }
  31. }
  32. \ **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.
  33. Methods
  34. -------
  35. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
  36. | void | :ref:`_run<class_EditorScript_method__run>` **(** **)** |virtual| |
  37. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
  38. | void | :ref:`add_root_node<class_EditorScript_method_add_root_node>` **(** :ref:`Node<class_Node>` node **)** |
  39. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
  40. | :ref:`EditorInterface<class_EditorInterface>` | :ref:`get_editor_interface<class_EditorScript_method_get_editor_interface>` **(** **)** |
  41. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
  42. | :ref:`Node<class_Node>` | :ref:`get_scene<class_EditorScript_method_get_scene>` **(** **)** |
  43. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
  44. Method Descriptions
  45. -------------------
  46. .. _class_EditorScript_method__run:
  47. - void **_run** **(** **)** |virtual|
  48. This method is executed by the Editor when **File > Run** is used.
  49. ----
  50. .. _class_EditorScript_method_add_root_node:
  51. - void **add_root_node** **(** :ref:`Node<class_Node>` node **)**
  52. Adds ``node`` as a child of the root node in the editor context.
  53. \ **Warning:** The implementation of this method is currently disabled.
  54. ----
  55. .. _class_EditorScript_method_get_editor_interface:
  56. - :ref:`EditorInterface<class_EditorInterface>` **get_editor_interface** **(** **)**
  57. Returns the :ref:`EditorInterface<class_EditorInterface>` singleton instance.
  58. ----
  59. .. _class_EditorScript_method_get_scene:
  60. - :ref:`Node<class_Node>` **get_scene** **(** **)**
  61. Returns the Editor's currently active scene.
  62. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  63. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  64. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  65. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  66. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  67. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`