Version: 2023.2

EditorWindow.wantsMouseEnterLeaveWindow

切换到手册
public bool wantsMouseEnterLeaveWindow ;

描述

检查是否已在此编辑器窗口的 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();
        }
    }   
}