Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
EditorScript
继承: RefCounted < Object
可用于为编辑器添加扩展功能的基础脚本。
描述
扩展该类并实现其 _run() 方法的脚本可以在编辑器运行时通过脚本编辑器的文件 > 运行菜单选项(或按 Ctrl + Shift + X)执行。这对于向 Godot 添加自定义的编辑内功能很有用。对于更复杂的添加,请考虑改用 EditorPlugin。
注意:扩展脚本需要启用 tool
工具模式。
示例:运行下面的脚本会输出“Godot 编辑器向你问好!”:
@tool
extends EditorScript
func _run():
print("Hello from the Godot Editor!")
using Godot;
[Tool]
public partial class HelloEditor : EditorScript
{
public override void _Run()
{
GD.Print("Godot 编辑器向你问好!");
}
}
注意:脚本在编辑器上下文中运行,这意味着输出在使用编辑器(stdout)启动的控制台窗口中可见,而不是通常的 Godot 输出停靠面板。
注意:EditorScript 是 RefCounted,这意味着它不再被引用时会被销毁。如果没有对脚本的引用,这可能会在异步操作期间导致错误。
方法
void |
_run() virtual |
void |
add_root_node(node: Node) |
get_editor_interface() const |
|
get_scene() const |
方法说明
void _run() virtual 🔗
当使用文件 > 运行时,此方法由编辑器执行。
void add_root_node(node: Node) 🔗
使 node
成为当前打开的场景的根。仅当场景为空时才有效。如果 node
是场景实例,则会创建一个继承场景。
EditorInterface get_editor_interface() const 🔗
已弃用: EditorInterface is a global singleton and can be accessed directly by its name.
返回 EditorInterface 单例实例。
返回正在编辑的(当前)场景的根 Node。相当于 EditorInterface.get_edited_scene_root()。