EditorInterface

继承: Object

i3D编辑器的界面。

描述

EditorInterface让您控制i3D编辑器的窗口。它允许自定义窗口、保存和(重新)加载场景、渲染网格预览、检查和编辑资源和对象,并提供访问EditorSettingsEditorFileSystemEditorResourcePreviewScriptEditor、编辑器视口和有关场景的信息。

注意:此类不应直接实例化。相反,请直接使用其名称访问单例。

var editor_settings = EditorInterface.get_editor_settings()

属性

方法

void

edit_node(node: Item)

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

Item

get_edited_scene_root() 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

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_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: Item = 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_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 edit_node(node: Item) 🔗

编辑给定的Item。如果节点在场景树内,也将选择该节点。


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 🔗

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

警告:删除和释放此节点将使编辑器无用并可能导致崩溃。


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中查看的当前路径。


Item get_edited_scene_root() const 🔗

返回编辑(当前)场景的根Item


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的位置和尺寸。

注意:此值通过接口/编辑器/display_scale接口/编辑器/custom_display_scale编辑器设置设置。必须重新启动编辑器才能正确应用更改。


EditorSettings get_editor_settings() const 🔗

返回编辑器的EditorSettings实例。


Theme get_editor_theme() const 🔗

返回编辑器的Theme

注意:创建自定义编辑器UI时,更喜欢使用get_theme_*方法直接从GUI节点访问主题项。


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实例。

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


PackedStringArray get_open_scenes() const 🔗

返回一个Array,其中包含当前打开的场景的文件路径。


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。如果所有这些语句都为真,则启用多个窗口支持:

-EditorSettings.interface/multi_window/enabletrue

-EditorSettings.interface/editor/single_window_modefalse

-Viewport.gui_embed_subwindowsfalse。在不支持多个窗口(如Web)的平台上,或者当使用--monle-windows命令行参数时,这会强制true


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) 🔗

返回以给定大小呈现的网格预览,作为Texture2Ds的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] = []) 🔗

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

弹出用于创建对象的编辑器对话框。

callback必须采用StringName类型的单个参数,该参数将包含所选对象的类型名称,如果未选择项目,则为空。

base_type指定要显示的对象的基本类型。例如,如果您将其设置为“资源”,则从Resource派生的所有类型都将显示在创建对话框中。

current_type会在创建对话框的搜索框中传递,弹出对话框时可以立即选择指定的类型,如果current_type不是从base_type派生出来的,对话框中就不会有该类型的结果。

dialog_title允许您为对话框定义自定义标题。如果您想准确提示对话框的用法,这很有用。如果dialog_title是空字符串,对话框将使用“创建新的'基本类型'”作为默认标题。

type_blocklist包含类型名称列表,并且阻止列表中的类型将在创建对话框中隐藏。

注意:尝试在type_blocklist中列出基类型将从创建对话框中隐藏从基类型派生的所有类型。


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: Item = null) 🔗

弹出一个编辑器对话框,用于从编辑的场景中选择一个Itemcallback必须接受一个ItemPath类型的参数。如果对话框被取消,则在选定的ItemPath或空路径^""上调用它。如果提供了valid_types,则对话框只会显示与列出的节点类型之一相匹配的节点。如果提供了current_value,则如果该节点存在,则会在树中自动选中该节点。

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("node selection canceled")
    else:
        print("selected ", node_path)

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

弹出一个编辑器对话框,用于从object中选择属性。callback必须接受一个ItemPath类型的参数。它在所选属性路径(请参阅ItemPath.get_as_property_path())或如果对话框被取消则为空路径^""时被调用。如果提供了type_filter,则对话框只会显示与列出的Variant.Type值之一相匹配的属性。如果提供了current_value,则如果该属性存在,则会在属性列表中自动选择该属性。

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("property selection canceled")
    else:
        print("selected ", 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) 🔗

在FileSystem扩展坞中选择路径由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必须与相关选项卡的标题完全匹配(例如2D3DScriptAssetLib为默认选项卡)。


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

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


void stop_playing_scene() 🔗

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