EditorScript

继承: RefCounted < Object

可用于为编辑器添加扩展功能的基础脚本。

描述

扩展该类并实现其 _run() 方法的脚本可以在编辑器运行时通过脚本编辑器的文件 > 运行菜单选项(或按 Ctrl + Shift + X)执行。这对于向 Godot 添加自定义的编辑内功能很有用。对于更复杂的添加,请考虑改用 EditorPlugin

如果扩展该类的脚本存在全局类名,则会包含在编辑器的命令面板中。

注意:扩展脚本需要启用 tool 工具模式。

示例:运行下面的脚本会输出“Godot 编辑器向你问好!”:

@tool
extends EditorScript

func _run():
    print("Hello from the Godot Editor!")

注意:EditorScript 是 RefCounted,这意味着它不再被引用时会被销毁。如果没有对脚本的引用,这可能会在异步操作期间导致错误。

方法

void

_run() virtual required

void

add_root_node(node: Node)

EditorInterface

get_editor_interface() const

Node

get_scene() const


方法说明

void _run() virtual required 🔗

当使用文件 > 运行时,此方法由编辑器执行。


void add_root_node(node: Node) 🔗

已弃用: Use EditorInterface.add_root_node() instead.

使 node 成为当前打开的场景的根。仅当场景为空时才有效。如果 node 是场景实例,则会创建一个继承场景。


EditorInterface get_editor_interface() const 🔗

已弃用: EditorInterface is a global singleton and can be accessed directly by its name.

返回 EditorInterface 单例实例。


Node get_scene() const 🔗

已弃用: Use EditorInterface.get_edited_scene_root() instead.

返回正在编辑的(当前)场景的根 Node。相当于 EditorInterface.get_edited_scene_root()