检查此编辑器窗口的 GUI 中是否接收 MouseEnterWindow 和 MouseLeaveWindow 事件。
如果设置为 true,则只要鼠标进入或离开窗口,窗口就会收到 OnGUI 调用。
注意:此函数不会自动触发 Repaint()。此外,当鼠标按钮按下时,进入或离开窗口不会触发任何事件,因为按下鼠标按钮会激活拖动模式(有关更多信息,请参阅 EventType.MouseDrag 和其他与拖动相关的事件)。
// Editor Script that shows how mouse enter and leave window events // get caught in the Editor window using UnityEditor; using UnityEngine; public class WantsMouseEnterLeaveWindowEx : EditorWindow { [MenuItem("Examples/wantsMouseEnterLeaveWindow example")] static void Init() { EditorWindow editorWindow = GetWindow(typeof(WantsMouseEnterLeaveWindowEx)); editorWindow.Show(); } public void OnGUI() { wantsMouseEnterLeaveWindow = EditorGUILayout.Toggle("Receive Enter/Leave: ", wantsMouseEnterLeaveWindow); EditorGUILayout.LabelField("Check Console for MouseEnter/LeaveWindow messages"); // Repaint the window as wantsMouseEnterLeaveWindow doesn't trigger a repaint automatically if (Event.current.type == EventType.MouseEnterWindow || Event.current.type == EventType.MouseLeaveWindow) { Debug.Log("Received event " + ((Event.current.type == EventType.MouseEnterWindow) ? "MouseEnterWindow" : "MouseLeaveWindow")); Repaint(); } } }