从此类派生以创建编辑器窗口。
创建自己的自定义编辑器窗口,这些窗口可以自由浮动,也可以作为选项卡停靠,就像 Unity 界面中的原生窗口一样。
通常使用菜单项打开编辑器窗口。
using UnityEditor; using UnityEngine; using UnityEngine.UIElements;
public class MyEditorWindow : EditorWindow { [MenuItem("Window/UI Toolkit/MyEditorWindow")] public static void ShowExample() { MyEditorWindow wnd = GetWindow<MyEditorWindow>(); wnd.titleContent = new GUIContent("MyEditorWindow"); }
public void CreateGUI() { // Each editor window contains a root VisualElement object VisualElement root = rootVisualElement;
// VisualElements objects can contain other VisualElement following a tree hierarchy Label label = new Label("Hello World!"); root.Add(label);
// Create button Button button = new Button(); button.name = "button"; button.text = "Button"; root.Add(button);
// Create toggle Toggle toggle = new Toggle(); toggle.name = "toggle"; toggle.label = "Toggle"; root.Add(toggle);
} }
focusedWindow | 当前已获得键盘焦点的 EditorWindow。(只读) |
focusedWindowChanged | Called whenever the focused editor window is changed. |
mouseOverWindow | 当前在鼠标光标下的 EditorWindow。(只读) |
autoRepaintOnSceneChange | Enable this property to automatically repaint the window when the SceneView is modified. |
dataModeController | An instance of IDataModeController to handle DataMode functionalities for the current window. |
docked | Returns true if EditorWindow is docked. |
hasFocus | Returns true if EditorWindow is focused. |
hasUnsavedChanges | This property specifies whether the Editor prompts the user to save or discard unsaved changes before the window closes. |
maximized | 此窗口是否已最大化? |
maxSize | The maximum size of this window when it is floating or modal. The maximum size is not used when the window is docked. |
minSize | The minimum size of this window when it is floating or modal. The minimum size is not used when the window is docked. |
overlayCanvas | The OverlayCanvas for this window. |
position | 窗口在屏幕空间中的理想位置。 |
rootVisualElement | 获取窗口层级视图的根视觉元素。 |
saveChangesMessage | The message that displays to the user if they are prompted to save |
titleContent | 用于绘制 EditorWindow 标题的 GUIContent。 |
wantsLessLayoutEvents | Specifies whether a layout pass is performed before all user events (for example, EventType.MouseDown or EventType.KeyDown), or is only performed before repaint events. |
wantsMouseEnterLeaveWindow | 检查是否已在此编辑器窗口的 GUI 中收到 MouseEnterWindow 和 MouseLeaveWindow 事件。 |
wantsMouseMove | 检查是否已在此编辑器窗口的 GUI 中收到 MouseMove 事件。 |
BeginWindows | 标记所有弹出窗口的开始区域。 |
Close | 关闭编辑器窗口。 |
DiscardChanges | Discards unsaved changes to the contents of the window. |
EndWindows | 关闭由 EditorWindow.BeginWindows 开始的窗口组。 |
Focus | 将键盘焦点移动到另一个 EditorWindow。 |
GetExtraPaneTypes | 获取与窗口关联的额外窗格。 |
RemoveNotification | 停止显示通知消息。 |
Repaint | 重绘窗口。 |
SaveChanges | Performs a save action on the contents of the window. |
SendEvent | 将事件发送到窗口。 |
Show | 显示 EditorWindow 窗口。 |
ShowAsDropDown | 显示包含下拉菜单和样式的窗口。 |
ShowAuxWindow | 在辅助窗口中显示编辑器窗口。 |
ShowModal | 显示模态编辑器窗口。 |
ShowModalUtility | Shows the EditorWindow as a floating modal window. |
ShowNotification | 显示通知消息。 |
ShowPopup | 使用弹出式框架显示编辑器窗口。 |
ShowUtility | 将 EditorWindow 显示为浮动实用程序窗口。 |
TryGetOverlay | Get an Overlay with matching ID from an EditorWindow canvas. |
OnBackingScaleFactorChanged | Called when the UI scaling for this EditorWindow is changed. |
CreateWindow | 创建类型为 T 的 EditorWindow。 |
FocusWindowIfItsOpen | 聚焦发现的第一个指定类型的 EditorWindow(如果已打开)。 |
GetWindow | Returns the first EditorWindow of type windowType which is currently on the screen. |
GetWindowWithRect | 返回当前屏幕上第一个 t 类型的 EditorWindow。 |
HasOpenInstances | 检查编辑器窗口是否已打开。 |
Awake | 在新窗口打开时调用。 |
CreateGUI | CreateGUI is called when the EditorWindow's rootVisualElement is ready to be populated. |
hasUnsavedChanges | This property specifies whether the Editor prompts the user to save or discard unsaved changes before the window closes. |
OnBecameInvisible | Called after the window is removed from a container view, or is no longer visible within a tabbed collection of EditorWindow. |
OnBecameVisible | Called after the window is added to a container view. |
OnDestroy | 调用 OnDestroy 以关闭 EditorWindow 窗口。 |
OnFocus | 在窗口获得键盘焦点时调用。 |
OnGUI | 在此处实现您自己的 Editor GUI。 |
OnHierarchyChange | 处理程序,用于在层级视图中的对象或对象组发生更改时发送的消息。 |
OnInspectorUpdate | OnInspectorUpdate 以每秒 10 帧的速度调用,以便检视面板有机会进行更新。 |
OnLostFocus | 在窗口失去键盘焦点时调用。 |
OnProjectChange | 处理程序,用于在项目状态发生更改时发送的消息。 |
OnSelectionChange | 每当选择发生更改时调用。 |
saveChangesMessage | The message that displays to the user if they are prompted to save |
Update | 在所有可见窗口上每秒调用多次。 |
GetInstanceID | Gets the instance ID of the object. |
ToString | 返回对象的名称。 |
Destroy | 移除 GameObject、组件或资源。 |
DestroyImmediate | 立即销毁对象 /obj/。强烈建议您改用 Destroy。 |
DontDestroyOnLoad | 在加载新的 Scene 时,请勿销毁 Object。 |
FindAnyObjectByType | Retrieves any active loaded object of Type type. |
FindFirstObjectByType | Retrieves the first active loaded object of Type type. |
FindObjectsByType | Retrieves a list of all loaded objects of Type type. |
Instantiate | 克隆 original 对象并返回克隆对象。 |
CreateInstance | 创建脚本化对象的实例。 |
bool | 该对象是否存在? |
operator != | 比较两个对象是否引用不同的对象。 |
operator == | 比较两个对象引用,判断它们是否引用同一个对象。 |
Awake | 当 ScriptableObject 脚本启动时调用此函数。 |
OnDisable | 当脚本化对象超出范围时调用此函数。 |
OnEnable | 当对象加载时调用此函数。 |
OnValidate | Editor-only function that Unity calls when the script is loaded or a value changes in the Inspector. |
Reset | 重置为默认值。 |