Files
godot-docs-l10n/classes/zh_CN/class_editorscript.rst

140 lines
5.2 KiB
ReStructuredText
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/4.2/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/EditorScript.xml.
.. _class_EditorScript:
EditorScript
============
**继承:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
可用于为编辑器添加扩展功能的基础脚本。
.. rst-class:: classref-introduction-group
描述
----
扩展该类并实现其 :ref:`_run<class_EditorScript_private_method__run>` 方法的脚本可以在编辑器运行时通过脚本编辑器的\ **文件 > 运行**\ 菜单选项(或按 :kbd:`Ctrl + Shift + X`\ )执行。这对于向 Godot 添加自定义的编辑内功能很有用。对于更复杂的添加,请考虑改用 :ref:`EditorPlugin<class_EditorPlugin>`\ 。
\ **注意:**\ 扩展脚本需要启用 ``tool`` 工具模式。
\ **示例脚本:**\
.. tabs::
.. code-tab:: gdscript
@tool
extends EditorScript
func _run():
print("Hello from the Godot Editor!")
.. code-tab:: csharp
using Godot;
[Tool]
public partial class HelloEditor : EditorScript
{
public override void _Run()
{
GD.Print("Hello from the Godot Editor!");
}
}
\ **注意:**\ 脚本在编辑器上下文中运行这意味着输出在使用编辑器stdout启动的控制台窗口中可见而不是通常的 Godot **输出**\ 停靠面板。
\ **注意:**\ EditorScript 是 :ref:`RefCounted<class_RefCounted>`\ ,这意味着它不再被引用时会被销毁。如果没有对脚本的引用,这可能会在异步操作期间导致错误。
.. rst-class:: classref-reftable-group
方法
----
.. table::
:widths: auto
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
| void | :ref:`_run<class_EditorScript_private_method__run>` **(** **)** |virtual| |
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
| void | :ref:`add_root_node<class_EditorScript_method_add_root_node>` **(** :ref:`Node<class_Node>` node **)** |
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
| :ref:`EditorInterface<class_EditorInterface>` | :ref:`get_editor_interface<class_EditorScript_method_get_editor_interface>` **(** **)** |const| |
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
| :ref:`Node<class_Node>` | :ref:`get_scene<class_EditorScript_method_get_scene>` **(** **)** |const| |
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
方法说明
--------
.. _class_EditorScript_private_method__run:
.. rst-class:: classref-method
void **_run** **(** **)** |virtual|
当使用\ **文件 > 运行**\ 时,此方法由编辑器执行。
.. rst-class:: classref-item-separator
----
.. _class_EditorScript_method_add_root_node:
.. rst-class:: classref-method
void **add_root_node** **(** :ref:`Node<class_Node>` node **)**
在编辑器上下文中,将 ``node`` 添加为根节点的子节点。
\ **警告:**\ 该方法的实现目前已被禁用。
.. rst-class:: classref-item-separator
----
.. _class_EditorScript_method_get_editor_interface:
.. rst-class:: classref-method
:ref:`EditorInterface<class_EditorInterface>` **get_editor_interface** **(** **)** |const|
返回 :ref:`EditorInterface<class_EditorInterface>` 单例实例。
\ *已废弃。*\ :ref:`EditorInterface<class_EditorInterface>` 是全局单例,可以使用其名称直接访问。
.. rst-class:: classref-item-separator
----
.. _class_EditorScript_method_get_scene:
.. rst-class:: classref-method
:ref:`Node<class_Node>` **get_scene** **(** **)** |const|
返回编辑器的当前活动场景。
.. |virtual| replace:: :abbr:`virtual (本方法通常需要用户覆盖才能生效。)`
.. |const| replace:: :abbr:`const (本方法没有副作用。不会修改该实例的任何成员变量。)`
.. |vararg| replace:: :abbr:`vararg (本方法除了在此处描述的参数外,还能够继续接受任意数量的参数。)`
.. |constructor| replace:: :abbr:`constructor (本方法用于构造某个类型。)`
.. |static| replace:: :abbr:`static (调用本方法无需实例,所以可以直接使用类名调用。)`
.. |operator| replace:: :abbr:`operator (本方法描述的是使用本类型作为左操作数的有效操作符。)`
.. |bitfield| replace:: :abbr:`BitField (这个值是由下列标志构成的位掩码整数。)`