EditorInterface

继承: Object

Godot 编辑器的接口。

描述

EditorInterface 允许控制 Godot 编辑器的窗口,包括自定义窗口,保存和重新加载场景,渲染网格预览,检查和编辑资源和对象,并提供对 EditorSettingsEditorFileSystemEditorResourcePreviewScriptEditor ,编辑器视口以及场景信息的访问。

注意: 这个类不应该被直接实例化。而是,直接通过名称访问单例。

var editor_settings = EditorInterface.get_editor_settings()

属性

bool

distraction_free_mode

bool

movie_maker_enabled

方法

void

add_root_node(node: Node)

Error

close_scene()

void

edit_node(node: Node)

void

edit_resource(resource: Resource)

void

edit_script(script: Script, line: int = -1, column: int = 0, grab_focus: bool = true)

Control

get_base_control() const

EditorCommandPalette

get_command_palette() const

String

get_current_directory() const

String

get_current_feature_profile() const

String

get_current_path() const

Node

get_edited_scene_root() const

String

get_editor_language() const

VBoxContainer

get_editor_main_screen() const

EditorPaths

get_editor_paths() const

float

get_editor_scale() const

EditorSettings

get_editor_settings() const

Theme

get_editor_theme() const

EditorToaster

get_editor_toaster() const

EditorUndoRedoManager

get_editor_undo_redo() const

SubViewport

get_editor_viewport_2d() const

SubViewport

get_editor_viewport_3d(idx: int = 0) const

FileSystemDock

get_file_system_dock() const

EditorInspector

get_inspector() const

float

get_node_3d_rotate_snap() const

float

get_node_3d_scale_snap() const

float

get_node_3d_translate_snap() const

Array[Node]

get_open_scene_roots() const

PackedStringArray

get_open_scenes() const

String

get_playing_scene() const

EditorFileSystem

get_resource_filesystem() const

EditorResourcePreview

get_resource_previewer() const

ScriptEditor

get_script_editor() const

PackedStringArray

get_selected_paths() const

EditorSelection

get_selection() const

void

inspect_object(object: Object, for_property: String = "", inspector_only: bool = false)

bool

is_multi_window_enabled() const

bool

is_node_3d_snap_enabled() const

bool

is_object_edited(object: Object) const

bool

is_playing_scene() const

bool

is_plugin_enabled(plugin: String) const

Array[Texture2D]

make_mesh_previews(meshes: Array[Mesh], preview_size: int)

void

mark_scene_as_unsaved()

void

open_scene_from_path(scene_filepath: String, set_inherited: bool = false)

void

play_current_scene()

void

play_custom_scene(scene_filepath: String)

void

play_main_scene()

void

popup_create_dialog(callback: Callable, base_type: StringName = "", current_type: String = "", dialog_title: String = "", type_blocklist: Array[StringName] = [])

void

popup_dialog(dialog: Window, rect: Rect2i = Rect2i(0, 0, 0, 0))

void

popup_dialog_centered(dialog: Window, minsize: Vector2i = Vector2i(0, 0))

void

popup_dialog_centered_clamped(dialog: Window, minsize: Vector2i = Vector2i(0, 0), fallback_ratio: float = 0.75)

void

popup_dialog_centered_ratio(dialog: Window, ratio: float = 0.8)

void

popup_method_selector(object: Object, callback: Callable, current_value: String = "")

void

popup_node_selector(callback: Callable, valid_types: Array[StringName] = [], current_value: Node = null)

void

popup_property_selector(object: Object, callback: Callable, type_filter: PackedInt32Array = PackedInt32Array(), current_value: String = "")

void

popup_quick_open(callback: Callable, base_types: Array[StringName] = [])

void

reload_scene_from_path(scene_filepath: String)

void

restart_editor(save: bool = true)

void

save_all_scenes()

Error

save_scene()

void

save_scene_as(path: String, with_preview: bool = true)

void

select_file(file: String)

void

set_current_feature_profile(profile_name: String)

void

set_main_screen_editor(name: String)

void

set_object_edited(object: Object, edited: bool)

void

set_plugin_enabled(plugin: String, enabled: bool)

void

stop_playing_scene()


属性说明

bool distraction_free_mode 🔗

  • void set_distraction_free_mode(value: bool)

  • bool is_distraction_free_mode_enabled()

如果为 true,将启用专注模式,该模式会隐藏侧边面板,增加主视图的可用空间。


bool movie_maker_enabled 🔗

  • void set_movie_maker_enabled(value: bool)

  • bool is_movie_maker_enabled()

如果为 true,则编辑器启用了 Movie Maker 模式。详见 MovieWriter


方法说明

void add_root_node(node: Node) 🔗

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


Error close_scene() 🔗

关闭当前活动的场景,关闭过程中忽略未保存的更改。成功时返回 @GlobalScope.OK,如果没有可关闭的场景则返回 @GlobalScope.ERR_DOES_NOT_EXIST


void edit_node(node: Node) 🔗

编辑给定的 Node。如果该节点在场景树内,将被选中。


void edit_resource(resource: Resource) 🔗

编辑给定的 Resource。如果该资源是 Script,你还可以使用 edit_script() 编辑,指定行列位置。


void edit_script(script: Script, line: int = -1, column: int = 0, grab_focus: bool = true) 🔗

编辑给定的 Script。还可以指定所打开脚本的行和列。打开脚本所使用的编辑器是由用户为该脚本的语言所配置,可能是外部编辑器。


Control get_base_control() const 🔗

返回 Godot 编辑器窗口的主容器。例如,你可以用它来检索容器的大小并相应地放置你的控件。

警告:删除和释放这个节点将使编辑器失效,并可能导致崩溃。


EditorCommandPalette get_command_palette() const 🔗

返回编辑器的 EditorCommandPalette 实例。

警告:删除和释放此节点,将使编辑器的一部分失去作用,并可能导致崩溃。


String get_current_directory() const 🔗

返回 FileSystemDock 中当前正在查看的目录。如果选择了一个文件,则将使用 String.get_base_dir() 返回其基本目录。


String get_current_feature_profile() const 🔗

返回当前激活的功能配置文件的名称。如果默认配置文件当前处于活动状态,则返回空字符串。

为了获取对 EditorFeatureProfile 的引用,你必须使用 EditorFeatureProfile.load_from_file() 加载该功能配置文件。

注意:通过用户界面创建的功能配置文件将从 feature_profiles 目录中的扩展名为 .profile 的文件加载。可以使用 EditorPaths.get_config_dir() 找到编辑器配置文件夹。


String get_current_path() const 🔗

返回在 FileSystemDock 中查看的当前路径。


Node get_edited_scene_root() const 🔗

返回正在编辑的(当前)场景的根 Node


String get_editor_language() const 🔗

Returns the language currently used for the editor interface.


VBoxContainer get_editor_main_screen() const 🔗

返回负责主屏幕插件和工具的编辑器控件。将其与实现了 EditorPlugin._has_main_screen() 的插件一起使用。

注意:该节点是一个 VBoxContainer,这意味着如果向其添加 Control 子节点,则需要将子节点的 Control.size_flags_vertical 设置为 Control.SIZE_EXPAND_FILL,以使其使用全部可用空间。

警告:移除和释放这个节点将使编辑器的一部分失去作用,并可能导致崩溃。


EditorPaths get_editor_paths() const 🔗

返回 EditorPaths 单例。


float get_editor_scale() const 🔗

返回编辑器 UI 的实际缩放(1.0 表示缩放为 100%)。可以用来调整由插件添加的用户 UI 的位置和尺寸。

注意:这个值是通过 EditorSettings.interface/editor/display_scaleEditorSettings.interface/editor/custom_display_scale 来设置。编辑器必须重新启动才能正确应用这些变化。


EditorSettings get_editor_settings() const 🔗

返回编辑器的 EditorSettings 实例。


Theme get_editor_theme() const 🔗

返回编辑器的 Theme

注意:创建自定义编辑器 UI 时,请优先直接通过 GUI 节点的 get_theme_* 方法来访问主题项目。


EditorToaster get_editor_toaster() const 🔗

返回编辑器的 EditorToaster


EditorUndoRedoManager get_editor_undo_redo() const 🔗

返回编辑器的 EditorUndoRedoManager


SubViewport get_editor_viewport_2d() const 🔗

返回 2D 编辑器 SubViewport。视口中没有相机。视图是直接进行变换的,可以使用 Viewport.global_canvas_transform 访问。


SubViewport get_editor_viewport_3d(idx: int = 0) const 🔗

返回指定的 3D 编辑器 SubViewport,编号从 03。可以通过 Viewport.get_camera_3d() 访问视口中的活动编辑器相机。


FileSystemDock get_file_system_dock() const 🔗

返回编辑器的文件系统面板 FileSystemDock 实例。

警告:移除和释放此节点将使编辑器的一部分失去作用,并可能导致崩溃。


EditorInspector get_inspector() const 🔗

返回编辑器的属性检查器 EditorInspector实例。

警告:删除和释放这个节点将使编辑器的一部分失去作用,并可能导致崩溃。


float get_node_3d_rotate_snap() const 🔗

Returns the amount of degrees the 3D editor's rotational snapping is set to.


float get_node_3d_scale_snap() const 🔗

Returns the amount of units the 3D editor's scale snapping is set to.


float get_node_3d_translate_snap() const 🔗

Returns the amount of units the 3D editor's translation snapping is set to.


Array[Node] get_open_scene_roots() const 🔗

返回包含当前所有已打开场景的根节点的数组。


PackedStringArray get_open_scenes() const 🔗

返回包含当前所有已打开场景的文件路径的数组。


String get_playing_scene() const 🔗

返回正在播放的场景名称。如果当前没有场景正在播放,返回一个空字符串。


EditorFileSystem get_resource_filesystem() const 🔗

返回编辑器的 EditorFileSystem 实例。


EditorResourcePreview get_resource_previewer() const 🔗

返回编辑器的 EditorResourcePreview 实例。


ScriptEditor get_script_editor() const 🔗

返回编辑器的脚本编辑器 ScriptEditor 实例。

警告:删除和释放这个节点将使编辑器的一部分失去作用,并可能导致崩溃。


PackedStringArray get_selected_paths() const 🔗

返回一个包含了 FileSystemDock 中当前所选文件(和目录)路径的数组。


EditorSelection get_selection() const 🔗

返回编辑器的 EditorSelection 实例。


void inspect_object(object: Object, for_property: String = "", inspector_only: bool = false) 🔗

在编辑器的检查器面板中显示给定 object 的属性。如果 inspector_onlytrue ,插件将不会试图编辑 object


bool is_multi_window_enabled() const 🔗

如果编辑器启用了多窗口支持,则返回 true。以下所有条件都满足时才会启用多窗口支持:


bool is_node_3d_snap_enabled() const 🔗

Returns true if the 3D editor currently has snapping mode enabled, and false otherwise.


bool is_object_edited(object: Object) const 🔗

Returns true if the object has been marked as edited through set_object_edited().


bool is_playing_scene() const 🔗

如果场景正在播放,返回 true,否则返回 false。暂停的场景将被视为正在播放。


bool is_plugin_enabled(plugin: String) const 🔗

如果启用了指定的 plugin,则返回 true。插件名称与其目录名称相同。


Array[Texture2D] make_mesh_previews(meshes: Array[Mesh], preview_size: int) 🔗

将以给定大小渲染的网格预览返回为元素类型为 Texture2D 的一个 Array


void mark_scene_as_unsaved() 🔗

将当前场景选项卡标记为未保存。


void open_scene_from_path(scene_filepath: String, set_inherited: bool = false) 🔗

打开位于给定路径的场景。如果 set_inheritedtrue,则会创建新的继承场景。


void play_current_scene() 🔗

播放当前活动的场景。


void play_custom_scene(scene_filepath: String) 🔗

播放文件路径所指定的场景。


void play_main_scene() 🔗

播放主场景。


void popup_create_dialog(callback: Callable, base_type: StringName = "", current_type: String = "", dialog_title: String = "", type_blocklist: Array[StringName] = []) 🔗

实验性: 未来版本中可能会修改或移除该方法。

Pops up an editor dialog for creating an object.

The callback must take a single argument of type String, which will contain the type name of the selected object (or the script path of the type, if the type is created from a script), or be an empty string if no item is selected.

The base_type specifies the base type of objects to display. For example, if you set this to "Resource", all types derived from Resource will display in the create dialog.

The current_type will be passed in the search box of the create dialog, and the specified type can be immediately selected when the dialog pops up. If the current_type is not derived from base_type, there will be no result of the type in the dialog.

The dialog_title allows you to define a custom title for the dialog. This is useful if you want to accurately hint the usage of the dialog. If the dialog_title is an empty string, the dialog will use "Create New 'Base Type'" as the default title.

The type_blocklist contains a list of type names, and the types in the blocklist will be hidden from the create dialog.

Note: Trying to list the base type in the type_blocklist will hide all types derived from the base type from the create dialog.


void popup_dialog(dialog: Window, rect: Rect2i = Rect2i(0, 0, 0, 0)) 🔗

使用 Window.popup_exclusive() 在编辑器 UI 中弹出 dialog。该对话框目前必须没有父级,否则该方法失败。

另见 Window.set_unparent_when_invisible()


void popup_dialog_centered(dialog: Window, minsize: Vector2i = Vector2i(0, 0)) 🔗

使用 Window.popup_exclusive_centered() 在编辑器 UI 中弹出 dialog。该对话框目前必须没有父级,否则该方法失败。

另见 Window.set_unparent_when_invisible()


void popup_dialog_centered_clamped(dialog: Window, minsize: Vector2i = Vector2i(0, 0), fallback_ratio: float = 0.75) 🔗

使用 Window.popup_exclusive_centered_clamped() 在编辑器 UI 中弹出 dialog。该对话框目前必须没有父级,否则该方法失败。

另见 Window.set_unparent_when_invisible()


void popup_dialog_centered_ratio(dialog: Window, ratio: float = 0.8) 🔗

使用 Window.popup_exclusive_centered_ratio() 在编辑器 UI 中弹出 dialog。该对话框目前必须没有父级,否则该方法失败。

另见 Window.set_unparent_when_invisible()


void popup_method_selector(object: Object, callback: Callable, current_value: String = "") 🔗

弹出编辑器对话框,用于选择 object 的方法。callback 回调必须接受单个 String 类型的参数,其中包含的是所选方法的名称,取消对话框时则为空。如果提供了 current_value 且对应方法存在,则会在方法列表中自动选中该方法。


void popup_node_selector(callback: Callable, valid_types: Array[StringName] = [], current_value: Node = null) 🔗

弹出编辑器对话框,用于选择所编辑场景中的 Nodecallback 必须接受单个类型为 NodePath 的参数。调用回调时会传入所选 NodePath,取消对话框时则为空路径 ^""。如果提供了 valid_types,则对话框只会显示与所列 Node 类型匹配的 Node。

示例:节点首次加入场景树时显示节点选择对话框:

func _ready():
    if Engine.is_editor_hint():
        EditorInterface.popup_node_selector(_on_node_selected, ["Button"])

func _on_node_selected(node_path):
    if node_path.is_empty():
        print("节点选择已取消")
    else:
        print("选中 ", node_path)

void popup_property_selector(object: Object, callback: Callable, type_filter: PackedInt32Array = PackedInt32Array(), current_value: String = "") 🔗

弹出编辑器对话框,用于选择 object 的属性。callback 必须接受单个类型为 NodePath 的参数。调用回调时会传入所选属性路径(见 NodePath.get_as_property_path()),取消对话框时则为空路径 ^""。如果提供了 type_filter,则对话框只会显示与所列 Variant.Type 值匹配的属性。

func _ready():
    if Engine.is_editor_hint():
        EditorInterface.popup_property_selector(this, _on_property_selected, [TYPE_INT])

func _on_property_selected(property_path):
    if property_path.is_empty():
        print("属性选择已取消")
    else:
        print("选中 ", property_path)

void popup_quick_open(callback: Callable, base_types: Array[StringName] = []) 🔗

弹出编辑器对话框,用于快速选择资源文件。callback 回调必须接受单个 String 类型的参数,其中包含的是所选资源的路径,取消对话框时则为空。如果提供了 base_types,则对话框中只会显示与这些类型相匹配的资源。仅支持派生自 Resource 的类型。


void reload_scene_from_path(scene_filepath: String) 🔗

重新加载给定路径的场景。


void restart_editor(save: bool = true) 🔗

重启编辑器。编辑器会关闭,然后再打开相同项目。如果 savetrue,则重启前会保存项目。


void save_all_scenes() 🔗

保存编辑器中打开的所有场景。


Error save_scene() 🔗

保存当前活动场景。返回 @GlobalScope.OK@GlobalScope.ERR_CANT_CREATE


void save_scene_as(path: String, with_preview: bool = true) 🔗

将当前活动的场景保存为位于 path 的文件。


void select_file(file: String) 🔗

在文件系统面板中选中文件,路径由 file 提供。


void set_current_feature_profile(profile_name: String) 🔗

使用给定的 profile_name 选择并激活指定的功能配置文件。将 profile_name 设置为空字符串以重置为默认功能配置文件。

可以使用 EditorFeatureProfile 类以编程方式创建功能配置文件。

注意:激活的功能配置文件必须位于 feature_profiles 目录中,且该文件的扩展名为 .profile。如果找不到配置文件,则会发生错误。可以使用 EditorPaths.get_config_dir() 找到编辑器配置文件夹。


void set_main_screen_editor(name: String) 🔗

将编辑器的当前主屏幕设置为 name 中指定的屏幕。name 必须与相关选项卡的文本完全匹配(默认选项卡为 2D3DScriptGameAssetLib)。


void set_object_edited(object: Object, edited: bool) 🔗

If edited is true, the object is marked as edited.

Note: This is primarily used by the editor for Resource based objects to track their modified state. For example, any changes to an open scene, a resource in the inspector, or an edited script will cause this method to be called with true. Saving the scene, script, or resource resets the edited state by calling this method with false.

Note: Each call to this method increments the object's edited version. This is used to track changes in the editor and to trigger when thumbnails should be regenerated for resources.


void set_plugin_enabled(plugin: String, enabled: bool) 🔗

设置插件的启用状态。插件名称与其目录名称相同。


void stop_playing_scene() 🔗

停止当前正在播放的场景。