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...
EditorInterface¶
继承: Object
Godot 编辑器的界面。
描述¶
EditorInterface 允许控制 Godot 编辑器的窗口,包括自定义窗口,保存和重新加载场景,渲染网格预览,检查和编辑资源和对象,并提供对 EditorSettings , EditorFileSystem , EditorResourcePreview , ScriptEditor ,编辑器视口以及场景信息的访问。
注意: 这个类不应该被直接实例化。而是,直接通过名称访问单例。
var editor_settings = EditorInterface.get_editor_settings()
// 在 C# 中,可以通过静态 Singleton 属性来访问。
EditorSettings settings = EditorInterface.Singleton.GetEditorSettings();
属性¶
方法¶
属性说明¶
bool distraction_free_mode
如果为 true
,将启用专注模式,该模式会隐藏侧边面板,增加主视图的可用空间。
bool movie_maker_enabled
如果为 true
,则编辑器启用了 Movie Maker 模式。详见 MovieWriter。
方法说明¶
void edit_node ( Node node )
编辑给定的 Node。如果该节点在场景树内,将被选中。
void edit_resource ( Resource resource )
编辑给定的 Resource。如果该资源是 Script,你还可以使用 edit_script 编辑,指定行列位置。
void edit_script ( Script script, int line=-1, int column=0, bool grab_focus=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。
VBoxContainer get_editor_main_screen ( ) const
返回负责主屏幕插件和工具的编辑器控件。将其与实现了 EditorPlugin._has_main_screen 的插件一起使用。
警告:移除和释放这个节点将使编辑器的一部分失去作用,并可能导致崩溃。
EditorPaths get_editor_paths ( ) const
返回 EditorPaths 单例。
float get_editor_scale ( ) const
返回编辑器用户 UI 的实际比例(1.0
表示比例为 100%)。这可以用来调整由插件添加的用户 UI 的位置和尺寸。
注意:这个值是通过 interface/editor/display_scale
和 interface/editor/custom_display_scale
编辑器设置项来设置。编辑器必须重新启动才能正确应用这些变化。
EditorSettings get_editor_settings ( ) const
返回编辑器的 EditorSettings 实例。
Theme get_editor_theme ( ) const
返回编辑器的 Theme。
注意:创建自定义编辑器 UI 时,请优先直接通过 GUI 节点的 get_theme_*
方法来访问主题项目。
SubViewport get_editor_viewport_2d ( ) const
返回 2D 编辑器 SubViewport。视口中没有相机。视图是直接进行变换的,可以使用 Viewport.global_canvas_transform 访问。
SubViewport get_editor_viewport_3d ( int idx=0 ) const
返回指定的 3D 编辑器 SubViewport,编号从 0
到 3
。可以通过 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, String for_property="", bool inspector_only=false )
在编辑器的检查器面板中显示给定 object
的属性。如果 inspector_only
为 true
,插件将不会试图编辑 object
。
bool is_playing_scene ( ) const
如果场景正在播放,返回 true
,否则返回 false
。暂停的场景将被视为正在播放。
bool is_plugin_enabled ( String plugin ) const
如果启用了指定的 plugin
,则返回 true
。插件名称与其目录名称相同。
Texture2D[] make_mesh_previews ( Mesh[] meshes, int preview_size )
将以给定大小渲染的网格预览返回为元素类型为 Texture2D 的一个 Array。
void mark_scene_as_unsaved ( )
将当前场景选项卡标记为未保存。
void open_scene_from_path ( String scene_filepath )
打开给定路径中的场景。
void play_current_scene ( )
播放当前活动的场景。
void play_custom_scene ( String scene_filepath )
播放文件路径所指定的场景。
void play_main_scene ( )
播放主场景。
void popup_dialog ( Window dialog, Rect2i rect=Rect2i(0, 0, 0, 0) )
使用 Window.popup_exclusive 在编辑器 UI 中弹出 dialog
。该对话框目前必须没有父级,否则该方法失败。
另见 Window.set_unparent_when_invisible。
void popup_dialog_centered ( Window dialog, Vector2i minsize=Vector2i(0, 0) )
使用 Window.popup_exclusive_centered 在编辑器 UI 中弹出 dialog
。该对话框目前必须没有父级,否则该方法失败。
另见 Window.set_unparent_when_invisible。
void popup_dialog_centered_clamped ( Window dialog, Vector2i minsize=Vector2i(0, 0), float fallback_ratio=0.75 )
使用 Window.popup_exclusive_centered_clamped 在编辑器 UI 中弹出 dialog
。该对话框目前必须没有父级,否则该方法失败。
另见 Window.set_unparent_when_invisible。
void popup_dialog_centered_ratio ( Window dialog, float ratio=0.8 )
使用 Window.popup_exclusive_centered_ratio 在编辑器 UI 中弹出 dialog
。该对话框目前必须没有父级,否则该方法失败。
另见 Window.set_unparent_when_invisible。
void reload_scene_from_path ( String scene_filepath )
重新加载给定路径的场景。
void restart_editor ( bool save=true )
重启编辑器。编辑器会关闭,然后再打开相同项目。如果 save
为 true
,则重启前会保存项目。
void save_all_scenes ( )
保存编辑器中打开的所有场景。
Error save_scene ( )
保存当前活动场景。返回 @GlobalScope.OK 或 @GlobalScope.ERR_CANT_CREATE。
void save_scene_as ( String path, bool with_preview=true )
将当前活动场景保存为 path
处的文件。
void select_file ( String file )
在文件系统面板中选中文件,路径由 file
提供。
void set_current_feature_profile ( String profile_name )
使用给定的 profile_name
选择并激活指定的功能配置文件。将 profile_name
设置为空字符串以重置为默认功能配置文件。
可以使用 EditorFeatureProfile 类以编程方式创建功能配置文件。
注意:激活的功能配置文件必须位于 feature_profiles
目录中,且该文件的扩展名为 .profile
。如果找不到配置文件,则会发生错误。可以使用 EditorPaths.get_config_dir 找到编辑器配置文件夹。
void set_main_screen_editor ( String name )
将编辑器的当前主屏幕设置为 name
中指定的屏幕。name
必须与相关选项卡的文本完全匹配(2D
、3D
、Script
、AssetLib
)。
void set_plugin_enabled ( String plugin, bool enabled )
设置插件的启用状态。插件名称与其目录名称相同。
void stop_playing_scene ( )
停止当前正在播放的场景。