public bool InterceptMouseEvent(IPanel panel, IMouseEvent ev) { if (!m_Context.pickElement) { return(false); } var evtBase = ev as EventBase; var evtType = evtBase.eventTypeId; var target = evtBase.target as VisualElement; // Ignore events on detached elements if (panel == null) { return(false); } if (((BaseVisualElementPanel)panel).ownerObject is HostView hostView && hostView.actualView is GameView) { var innerArea = panel.GetRootVisualElement(); var gameViewPadding = (innerArea.parent.contentRect.height - innerArea.contentRect.height) * Vector2.up + innerArea.layout.position; // Measured to: gameViewPadding = new Vector2(1, 40) // Send event to runtime panels from closest to deepest var panels = UIElementsRuntimeUtility.GetSortedPlayerPanels(); for (var i = panels.Count - 1; i >= 0; i--) { if (SendEventToRuntimePanel((BaseRuntimePanel)panels[i], evtBase, gameViewPadding)) { return(true); } } // If no RuntimePanel catches it, select GameView editor panel and let interception fall through. if (evtType == MouseMoveEvent.TypeId() && m_Context.selectedElement != target) { OnPickMouseOver(target, panel); } }
public void OnPostMouseEvent(IPanel panel, IMouseEvent ev) { var isRightClick = (ev as MouseUpEvent)?.button == (int)MouseButton.RightMouse; if (!isRightClick || m_PickElement) { return; } // Ignore events on detached elements and on this debugger if (panel == null || panel == rootVisualElement.panel) { return; } var evtBase = ev as EventBase; var evtType = evtBase.eventTypeId; var target = evtBase.target as VisualElement; var targetIsImguiContainer = target is IMGUIContainer; if (target != null) { // If right clicking on the root IMGUIContainer try to select the root container instead if (targetIsImguiContainer && target == panel.visualTree[0]) { // Pick the root container var root = panel.GetRootVisualElement(); if (root != null && root.childCount > 0 && root.worldBound.Contains(ev.mousePosition)) { target = root; targetIsImguiContainer = false; } } if (!targetIsImguiContainer) { ShowInspectMenu(target); } } }