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 工具模式。
示例脚本:
@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("Hello from the Godot Editor!");
}
}
注意:脚本在编辑器上下文中运行,这意味着输出在使用编辑器(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) 🔗
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.
EditorInterface get_editor_interface() const 🔗
已弃用: EditorInterface is a global singleton and can be accessed directly by its name.
返回 EditorInterface 单例实例。
Returns the edited (current) scene's root Node. Equivalent of EditorInterface.get_edited_scene_root.