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();
屬性
方法
屬性說明
如果為 true,將啟用專注模式,該模式會隱藏側邊面板,增加主視圖的可用空間。
如果為 true,則編輯器啟用了 Movie Maker 模式。詳見 MovieWriter。
方法說明
void add_root_node(node: Node) 🔗
Makes node root of the currently opened scene. Only works if the scene is empty. If the node is a scene instance, an inheriting scene will be created.
Closes the currently active scene, discarding any pending changes in the process. Returns @GlobalScope.OK on success or @GlobalScope.ERR_DOES_NOT_EXIST if there is no scene to close.
編輯給定的 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 🔗
Returns the editor control responsible for main screen plugins and tools. Use it with plugins that implement EditorPlugin._has_main_screen().
Note: This node is a VBoxContainer, which means that if you add a Control child to it, you need to set the child's Control.size_flags_vertical to Control.SIZE_EXPAND_FILL to make it use the full available space.
Warning: Removing and freeing this node will render a part of the editor useless and may cause a crash.
EditorPaths get_editor_paths() const 🔗
返回 EditorPaths 單例。
float get_editor_scale() const 🔗
Returns the actual scale of the editor UI (1.0 being 100% scale). This can be used to adjust position and dimensions of the UI added by plugins.
Note: This value is set via the EditorSettings.interface/editor/appearance/display_scale and EditorSettings.interface/editor/appearance/custom_display_scale settings. The editor must be restarted for changes to be properly applied.
EditorSettings get_editor_settings() const 🔗
返回編輯器的 EditorSettings 實例。
Theme get_editor_theme() const 🔗
返回編輯器的 Theme。
注意:建立自訂編輯器 UI 時,請優先直接通過 GUI 節點的 get_theme_* 方法來存取主題專案。
EditorToaster get_editor_toaster() const 🔗
Returns the editor's EditorToaster.
EditorUndoRedoManager get_editor_undo_redo() const 🔗
Returns the editor's EditorUndoRedoManager.
SubViewport get_editor_viewport_2d() const 🔗
返回 2D 編輯器 SubViewport。視口中沒有相機。視圖是直接進行變換的,可以使用 Viewport.global_canvas_transform 存取。
SubViewport get_editor_viewport_3d(idx: int = 0) const 🔗
返回指定的 3D 編輯器 SubViewport,編號從 0 到 3。可以通過 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 🔗
Returns an array with references to the root nodes of the currently opened scenes.
PackedStringArray get_open_scenes() const 🔗
Returns an array with the file paths of the currently opened scenes.
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 實例。
PackedStringArray get_unsaved_scenes() const 🔗
Returns an array of file paths of currently unsaved scenes.
void inspect_object(object: Object, for_property: String = "", inspector_only: bool = false) 🔗
顯示指定的屬性在指定的 object 上,於編輯器的屬性檢視器面板中。如果 inspector_only 是 true,外掛程式將不會嘗試編輯 object。
bool is_multi_window_enabled() const 🔗
Returns true if multiple window support is enabled in the editor. Multiple window support is enabled if all of these statements are true:
EditorSettings.interface/editor/display/single_window_mode is
false.Viewport.gui_embed_subwindows is
false. This is forced totrueon platforms that don't support multiple windows such as Web, or when the--single-windowcommand line argument is used.
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) 🔗
Opens the scene at the given path. If set_inherited is true, creates a new inherited scene.
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 = "") 🔗
Pops up an editor dialog for selecting a method from object. The callback must take a single argument of type String which will contain the name of the selected method or be empty if the dialog is canceled. If current_value is provided, the method will be selected automatically in the method list, if it exists.
void popup_node_selector(callback: Callable, valid_types: Array[StringName] = [], current_value: Node = null) 🔗
Pops up an editor dialog for selecting a Node from the edited scene. The callback must take a single argument of type NodePath. It is called on the selected NodePath or the empty path ^"" if the dialog is canceled. If valid_types is provided, the dialog will only show Nodes that match one of the listed Node types. If current_value is provided, the Node will be automatically selected in the tree, if it exists.
Example: Display the node selection dialog as soon as this node is added to the tree for the first time:
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 = "") 🔗
Pops up an editor dialog for selecting properties from object. The callback must take a single argument of type NodePath. It is called on the selected property path (see NodePath.get_as_property_path()) or the empty path ^"" if the dialog is canceled. If type_filter is provided, the dialog will only show properties that match one of the listed Variant.Type values. If current_value is provided, the property will be selected automatically in the property list, if it exists.
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] = []) 🔗
Pops up an editor dialog for quick selecting a resource file. The callback must take a single argument of type String which will contain the path of the selected resource or be empty if the dialog is canceled. If base_types is provided, the dialog will only show resources that match these types. Only types deriving from Resource are supported.
void reload_scene_from_path(scene_filepath: String) 🔗
Reloads the scene at the given path. Fails if the scene is not open.
void restart_editor(save: bool = true) 🔗
重啟編輯器。編輯器會關閉,然後再打開相同專案。如果 save 為 true,則重啟前會保存專案。
void save_all_scenes() 🔗
管理編輯器中的 SceneTree 選擇。
保存場景。返回 @GlobalScope.OK 或 @GlobalScope.ERR_CANT_CREATE。
void save_scene_as(path: String, with_preview: bool = true) 🔗
Saves the currently active scene as a file at 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) 🔗
Sets the editor's current main screen to the one specified in name. name must match the title of the tab in question exactly (e.g. 2D, 3D, Script, Game, or Asset Store for default tabs).
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() 🔗
停止目前正在播放的場景。