实现此接口可在 EditorWindow 中启用叠加层。
当实现 ISupportsOverlays 时,一个叠加层画布会自动添加到您的 EditorWindow 的 VisualElement 树中。 OverlayAttribute 现在可以将此窗口类型指定为注册 Overlay 的有效目标。
using System; using UnityEditor; using UnityEditor.Overlays; using UnityEngine; using UnityEngine.UIElements; class EditorWindowOverlayExample : EditorWindow, ISupportsOverlays { [MenuItem("Window/Overlay Supported Window Example")] static void Init() => GetWindow<EditorWindowOverlayExample>(); void OnGUI() { GUILayout.Label("Here is some text"); GUILayout.FlexibleSpace(); GUILayout.Label("Plus some more text, but on the bottom of the screen."); } } [Overlay(typeof(EditorWindowOverlayExample), "Is Mouse Hovering Me?", true)] class IsMouseHoveringMe : Overlay { Label m_MouseLabel; public override VisualElement CreatePanelContent() { m_MouseLabel = new Label(); m_MouseLabel.style.minHeight = 40; m_MouseLabel.RegisterCallback<MouseEnterEvent>(evt => m_MouseLabel.text = "Mouse is hovering this Overlay content!"); m_MouseLabel.RegisterCallback<MouseLeaveEvent>(evt => m_MouseLabel.text = "Mouse is not hovering this Overlay content."); return m_MouseLabel; } }