Version: 2021.1

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("Example/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 doesnt 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(); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961