Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

EditorScript

继承: RefCounted < Object

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

描述

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

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

示例脚本:

@tool
extends EditorScript

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

注意:脚本在编辑器上下文中运行,这意味着输出在使用编辑器(stdout)启动的控制台窗口中可见,而不是通常的 Godot 输出停靠面板。

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

方法

void

_run ( ) virtual

void

add_root_node ( Node node )

EditorInterface

get_editor_interface ( ) const

Node

get_scene ( ) const


方法说明

void _run ( ) virtual

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


void add_root_node ( Node node )

在编辑器上下文中,将 node 添加为根节点的子节点。

警告:该方法的实现目前已被禁用。


EditorInterface get_editor_interface ( ) const

返回 EditorInterface 单例实例。

已废弃。EditorInterface 是全局单例,可以使用其名称直接访问。


Node get_scene ( ) const

返回编辑器的当前活动场景。