コード例 #1
0
        static void SetBestTargetForEvent(EventBase evt, IPanel panel)
        {
            UpdateElementUnderPointer(evt, panel, out VisualElement elementUnderPointer);

            if (evt.target == null && elementUnderPointer != null)
            {
                evt.propagateToIMGUI = false;
                evt.target           = elementUnderPointer;
            }
            else if (evt.target == null && elementUnderPointer == null)
            {
                // Event occurred outside the window.
                // Fix for case 1306631 - a MouseUp event received outside of the GameView
                // is re-directed to the DockArea IMGUIContainer. Otherwise send the event
                // to the visual tree root and don't modify evt.propagateToIMGUI, allowing
                // MouseLeaveWindow events may be received via trickle down traversal.
                if (panel?.contextType == ContextType.Editor && evt.eventTypeId == PointerUpEvent.TypeId())
                {
                    evt.target = (panel as Panel)?.rootIMGUIContainer;
                }
                else
                {
                    evt.target = panel?.visualTree;
                }
            }
            else if (evt.target != null)
            {
                evt.propagateToIMGUI = false;
            }
        }
コード例 #2
0
 void OnClickEvent(EventBase evt)
 {
     if (evt.eventTypeId == MouseUpEvent.TypeId())
     {
         var ce = (IMouseEvent)evt;
         if (ce.button == (int)MouseButton.LeftMouse)
         {
             ToggleValue();
         }
     }
     else if (evt.eventTypeId == PointerUpEvent.TypeId() || evt.eventTypeId == ClickEvent.TypeId())
     {
         var ce = (IPointerEvent)evt;
         if (ce.button == (int)MouseButton.LeftMouse)
         {
             ToggleValue();
         }
     }
 }
コード例 #3
0
        public override void ExecuteDefaultActionAtTarget(EventBase evt)
        {
            base.ExecuteDefaultActionAtTarget(evt);

            if (keyboardOnScreen != null)
            {
                return;
            }

            var edition = textElement.edition;

            if (!edition.isReadOnly && evt.eventTypeId == PointerDownEvent.TypeId())
            {
                // CaptureMouse is preventing WebGL from processing pointerDown event in
                // TextInputFieldBase during the Javascript event handler, preventing the
                // keyboard from being displayed. Disable the capture behavior for WebGL.
                textElement.CaptureMouse();
                m_LastPointerDownTarget = evt.target as VisualElement;
            }
            else if (!edition.isReadOnly && evt.eventTypeId == PointerUpEvent.TypeId())
            {
                textElement.ReleaseMouse();
                if (m_LastPointerDownTarget == null || !m_LastPointerDownTarget.worldBound.Contains(((PointerUpEvent)evt).position))
                {
                    return;
                }

                m_LastPointerDownTarget = null;

                edition.UpdateText(editingUtilities.text);

                OpenTouchScreenKeyboard();

                if (keyboardOnScreen != null)
                {
                    PollTouchScreenKeyboard();
                }

                // Scroll offset might need to be updated
                edition.UpdateScrollOffset?.Invoke();
                evt.StopPropagation();
            }
        }
コード例 #4
0
 bool ProcessClick(EventBase evt)
 {
     if (evt.eventTypeId == MouseUpEvent.TypeId())
     {
         var ce = (IMouseEvent)evt;
         if (ce.button == (int)MouseButton.LeftMouse)
         {
             return(true);
         }
     }
     else if (evt.eventTypeId == PointerUpEvent.TypeId() || evt.eventTypeId == ClickEvent.TypeId())
     {
         var ce = (IPointerEvent)evt;
         if (ce.button == (int)MouseButton.LeftMouse)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #5
0
        public override void ExecuteDefaultActionAtTarget(EventBase evt)
        {
            base.ExecuteDefaultActionAtTarget(evt);

            if (!textInputField.isReadOnly && evt.eventTypeId == PointerDownEvent.TypeId() && editorEngine.keyboardOnScreen == null)
            {
                m_LastPointerDownTarget = evt.target as VisualElement;
            }
            else if (!textInputField.isReadOnly && evt.eventTypeId == PointerUpEvent.TypeId() && editorEngine.keyboardOnScreen == null)
            {
                var pointerUpEvent = evt as PointerUpEvent;
                if (m_LastPointerDownTarget == null || !m_LastPointerDownTarget.worldBound.Contains(pointerUpEvent.position))
                {
                    return;
                }

                textInputField.SyncTextEngine();
                textInputField.UpdateText(editorEngine.text);

                editorEngine.keyboardOnScreen = TouchScreenKeyboard.Open(textInputField.text,
                                                                         TouchScreenKeyboardType.Default,
                                                                         true, // autocorrection
                                                                         editorEngine.multiline,
                                                                         textInputField.isPasswordField);

#if UNITY_IOS || UNITY_ANDROID
                s_KeyboardOnScreen = editorEngine.keyboardOnScreen;
#endif

                if (editorEngine.keyboardOnScreen != null)
                {
                    PollTouchScreenKeyboard();
                }

                // Scroll offset might need to be updated
                editorEngine.UpdateScrollOffset();
                evt.StopPropagation();
            }
        }
コード例 #6
0
        void UpdateEventbaseInfo(EventDebuggerEventRecord eventBase, IEventHandler focused, IEventHandler capture)
        {
            ClearEventbaseInfo();

            if (eventBase == null)
            {
                return;
            }

            m_EventbaseInfo.text += "Focused element: " + EventDebugger.GetObjectDisplayName(focused) + "\n";
            m_EventbaseInfo.text += "Capture element: " + EventDebugger.GetObjectDisplayName(capture) + "\n";

            if (eventBase.eventTypeId == MouseMoveEvent.TypeId() ||
                eventBase.eventTypeId == MouseOverEvent.TypeId() ||
                eventBase.eventTypeId == MouseOutEvent.TypeId() ||
                eventBase.eventTypeId == MouseDownEvent.TypeId() ||
                eventBase.eventTypeId == MouseUpEvent.TypeId() ||
                eventBase.eventTypeId == MouseEnterEvent.TypeId() ||
                eventBase.eventTypeId == MouseLeaveEvent.TypeId() ||
                eventBase.eventTypeId == DragEnterEvent.TypeId() ||
                eventBase.eventTypeId == DragLeaveEvent.TypeId() ||
                eventBase.eventTypeId == DragUpdatedEvent.TypeId() ||
                eventBase.eventTypeId == DragPerformEvent.TypeId() ||
                eventBase.eventTypeId == DragExitedEvent.TypeId() ||
                eventBase.eventTypeId == ContextClickEvent.TypeId() ||
                eventBase.eventTypeId == PointerMoveEvent.TypeId() ||
                eventBase.eventTypeId == PointerOverEvent.TypeId() ||
                eventBase.eventTypeId == PointerOutEvent.TypeId() ||
                eventBase.eventTypeId == PointerDownEvent.TypeId() ||
                eventBase.eventTypeId == PointerUpEvent.TypeId() ||
                eventBase.eventTypeId == PointerCancelEvent.TypeId() ||
                eventBase.eventTypeId == PointerStationaryEvent.TypeId() ||
                eventBase.eventTypeId == PointerEnterEvent.TypeId() ||
                eventBase.eventTypeId == PointerLeaveEvent.TypeId())
            {
                m_EventbaseInfo.text += "Mouse position: " + eventBase.mousePosition + "\n";
                m_EventbaseInfo.text += "Modifiers: " + eventBase.modifiers + "\n";
            }

            if (eventBase.eventTypeId == KeyDownEvent.TypeId() ||
                eventBase.eventTypeId == KeyUpEvent.TypeId())
            {
                m_EventbaseInfo.text += "Modifiers: " + eventBase.modifiers + "\n";
            }

            if (eventBase.eventTypeId == MouseDownEvent.TypeId() ||
                eventBase.eventTypeId == MouseUpEvent.TypeId() ||
                eventBase.eventTypeId == PointerDownEvent.TypeId() ||
                eventBase.eventTypeId == PointerUpEvent.TypeId() ||
                eventBase.eventTypeId == DragUpdatedEvent.TypeId() ||
                eventBase.eventTypeId == DragPerformEvent.TypeId() ||
                eventBase.eventTypeId == DragExitedEvent.TypeId())
            {
                m_EventbaseInfo.text += "Button: " + (eventBase.button == 0 ? "Left" : eventBase.button == 1 ? "Middle" : "Right") + "\n";
                m_EventbaseInfo.text += "Click count: " + eventBase.clickCount + "\n";
            }

            if (eventBase.eventTypeId == MouseMoveEvent.TypeId() ||
                eventBase.eventTypeId == MouseOverEvent.TypeId() ||
                eventBase.eventTypeId == MouseOutEvent.TypeId() ||
                eventBase.eventTypeId == MouseDownEvent.TypeId() ||
                eventBase.eventTypeId == MouseUpEvent.TypeId() ||
                eventBase.eventTypeId == MouseEnterEvent.TypeId() ||
                eventBase.eventTypeId == MouseLeaveEvent.TypeId() ||
                eventBase.eventTypeId == DragEnterEvent.TypeId() ||
                eventBase.eventTypeId == DragLeaveEvent.TypeId() ||
                eventBase.eventTypeId == DragUpdatedEvent.TypeId() ||
                eventBase.eventTypeId == DragPerformEvent.TypeId() ||
                eventBase.eventTypeId == DragExitedEvent.TypeId() ||
                eventBase.eventTypeId == ContextClickEvent.TypeId() ||
                eventBase.eventTypeId == WheelEvent.TypeId() ||
                eventBase.eventTypeId == PointerMoveEvent.TypeId() ||
                eventBase.eventTypeId == PointerOverEvent.TypeId() ||
                eventBase.eventTypeId == PointerOutEvent.TypeId() ||
                eventBase.eventTypeId == PointerDownEvent.TypeId() ||
                eventBase.eventTypeId == PointerUpEvent.TypeId() ||
                eventBase.eventTypeId == PointerCancelEvent.TypeId() ||
                eventBase.eventTypeId == PointerStationaryEvent.TypeId() ||
                eventBase.eventTypeId == PointerEnterEvent.TypeId() ||
                eventBase.eventTypeId == PointerLeaveEvent.TypeId())
            {
                m_EventbaseInfo.text += "Pressed buttons: " + eventBase.pressedButtons + "\n";
            }

            if (eventBase.eventTypeId == WheelEvent.TypeId())
            {
                m_EventbaseInfo.text += "Mouse delta: " + eventBase.delta + "\n";
            }

            if (eventBase.eventTypeId == KeyDownEvent.TypeId() ||
                eventBase.eventTypeId == KeyUpEvent.TypeId())
            {
                if (char.IsControl(eventBase.character))
                {
                    m_EventbaseInfo.text += "Character: \\" + (byte)(eventBase.character) + "\n";
                }
                else
                {
                    m_EventbaseInfo.text += "Character: " + eventBase.character + "\n";
                }

                m_EventbaseInfo.text += "Key code: " + eventBase.keyCode + "\n";
            }

            if (eventBase.eventTypeId == ValidateCommandEvent.TypeId() ||
                eventBase.eventTypeId == ExecuteCommandEvent.TypeId())
            {
                m_EventbaseInfo.text += "Command: " + eventBase.commandName + "\n";
            }
        }
コード例 #7
0
        internal void CommitElementUnderPointers(EventDispatcher dispatcher)
        {
            for (var i = 0; i < m_TopElementUnderPointer.Length; i++)
            {
                if (m_TopElementUnderPointer[i] == m_PendingTopElementUnderPointer[i])
                {
                    continue;
                }

                if (m_TriggerPointerEvent[i] == null && m_TriggerMouseEvent[i] == null)
                {
                    using (new EventDispatcherGate(dispatcher))
                    {
                        Vector2 position = PointerDeviceState.GetPointerPosition(i);

                        PointerEventsHelper.SendOverOut(m_TopElementUnderPointer[i],
                                                        m_PendingTopElementUnderPointer[i], null,
                                                        position, i);
                        PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>(
                            m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, position, i);

                        if (i == PointerId.mousePointerId)
                        {
                            MouseEventsHelper.SendMouseOverMouseOut(m_TopElementUnderPointer[i],
                                                                    m_PendingTopElementUnderPointer[i],
                                                                    null, position);
                            MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>(
                                m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, position);
                        }
                    }
                }

                if (m_TriggerPointerEvent[i] != null)
                {
                    if ((m_TriggerPointerEvent[i] as EventBase)?.eventTypeId == PointerMoveEvent.TypeId() ||
                        (m_TriggerPointerEvent[i] as EventBase)?.eventTypeId == PointerDownEvent.TypeId() ||
                        (m_TriggerPointerEvent[i] as EventBase)?.eventTypeId == PointerUpEvent.TypeId() ||
                        (m_TriggerPointerEvent[i] as EventBase)?.eventTypeId == PointerCancelEvent.TypeId())
                    {
                        using (new EventDispatcherGate(dispatcher))
                        {
                            PointerEventsHelper.SendOverOut(m_TopElementUnderPointer[i],
                                                            m_PendingTopElementUnderPointer[i],
                                                            m_TriggerPointerEvent[i], m_TriggerPointerEvent[i].position, i);
                            PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>(
                                m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i],
                                m_TriggerPointerEvent[i], m_TriggerPointerEvent[i].position, i);
                        }
                    }

                    m_TriggerPointerEvent[i] = null;
                }

                if (m_TriggerMouseEvent[i] != null)
                {
                    if ((m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseMoveEvent.TypeId() ||
                        (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseDownEvent.TypeId() ||
                        (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseUpEvent.TypeId() ||
                        (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == WheelEvent.TypeId())
                    {
                        using (new EventDispatcherGate(dispatcher))
                        {
                            MouseEventsHelper.SendMouseOverMouseOut(m_TopElementUnderPointer[i],
                                                                    m_PendingTopElementUnderPointer[i],
                                                                    m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition);
                            MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>(
                                m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i],
                                m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition);
                        }
                    }
                    else if ((m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseEnterWindowEvent.TypeId() ||
                             (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseLeaveWindowEvent.TypeId()
                             )
                    {
                        using (new EventDispatcherGate(dispatcher))
                        {
                            PointerEventsHelper.SendOverOut(m_TopElementUnderPointer[i],
                                                            m_PendingTopElementUnderPointer[i], null,
                                                            m_TriggerMouseEvent[i].mousePosition, i);
                            PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>(
                                m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null,
                                m_TriggerMouseEvent[i].mousePosition, i);

                            if (i == PointerId.mousePointerId)
                            {
                                MouseEventsHelper.SendMouseOverMouseOut(m_TopElementUnderPointer[i],
                                                                        m_PendingTopElementUnderPointer[i],
                                                                        m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition);
                                MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>(
                                    m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i],
                                    m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition);
                            }
                        }
                    }
                    else if ((m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == DragUpdatedEvent.TypeId() ||
                             (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == DragExitedEvent.TypeId())
                    {
                        using (new EventDispatcherGate(dispatcher))
                        {
                            PointerEventsHelper.SendOverOut(m_TopElementUnderPointer[i],
                                                            m_PendingTopElementUnderPointer[i], null,
                                                            m_TriggerMouseEvent[i].mousePosition, i);
                            PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>(
                                m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null,
                                m_TriggerMouseEvent[i].mousePosition, i);

                            MouseEventsHelper.SendMouseOverMouseOut(m_TopElementUnderPointer[i],
                                                                    m_PendingTopElementUnderPointer[i],
                                                                    m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition);
                            MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>(
                                m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i],
                                m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition);
                            MouseEventsHelper.SendEnterLeave <DragLeaveEvent, DragEnterEvent>(
                                m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i],
                                m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition);
                        }
                    }

                    m_TriggerMouseEvent[i] = null;
                }

                m_TopElementUnderPointer[i] = m_PendingTopElementUnderPointer[i];
            }
        }
コード例 #8
0
        internal void CommitElementUnderPointers(EventDispatcher dispatcher)
        {
            for (var i = 0; i < m_TopElementUnderPointer.Length; i++)
            {
                var triggerPointerEvent = m_TriggerPointerEvent[i];
                var previous            = m_TopElementUnderPointer[i];
                var current             = m_PendingTopElementUnderPointer[i];

                if (current == previous)
                {
                    if (triggerPointerEvent != null)
                    {
                        var pos3d = triggerPointerEvent.position;
                        m_PickingPointerPositions[i] = new Vector2(pos3d.x, pos3d.y);
                    }
                    else if (m_TriggerMouseEvent[i] != null)
                    {
                        m_PickingPointerPositions[i] = m_TriggerMouseEvent[i].mousePosition;
                    }

                    continue;
                }

                m_TopElementUnderPointer[i] = current;

                if (triggerPointerEvent == null && m_TriggerMouseEvent[i] == null)
                {
                    using (new EventDispatcherGate(dispatcher))
                    {
                        Vector2 position = PointerDeviceState.GetPointerPosition(i);

                        PointerEventsHelper.SendOverOut(previous, current, null, position, i);
                        PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>(
                            previous, current, null, position, i);

                        m_PickingPointerPositions[i] = position;
                        if (i == PointerId.mousePointerId)
                        {
                            MouseEventsHelper.SendMouseOverMouseOut(previous, current, null, position);
                            MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>(
                                previous, current, null, position);
                        }
                    }
                }

                if (triggerPointerEvent != null)
                {
                    var pos3d = triggerPointerEvent.position;
                    m_PickingPointerPositions[i] = new Vector2(pos3d.x, pos3d.y);

                    var baseEvent = triggerPointerEvent as EventBase;
                    if (baseEvent != null && (
                            baseEvent.eventTypeId == PointerMoveEvent.TypeId() ||
                            baseEvent.eventTypeId == PointerDownEvent.TypeId() ||
                            baseEvent.eventTypeId == PointerUpEvent.TypeId() ||
                            baseEvent.eventTypeId == PointerCancelEvent.TypeId()))
                    {
                        using (new EventDispatcherGate(dispatcher))
                        {
                            PointerEventsHelper.SendOverOut(previous, current, triggerPointerEvent, pos3d, i);
                            PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>(
                                previous, current, triggerPointerEvent, pos3d, i);
                        }
                    }
                }

                m_TriggerPointerEvent[i] = null;

                var triggerMouseEvent = m_TriggerMouseEvent[i];
                if (triggerMouseEvent != null)
                {
                    Vector2 mousePos = triggerMouseEvent.mousePosition;
                    m_PickingPointerPositions[i] = mousePos;
                    var baseEvent = triggerMouseEvent as EventBase;
                    if (baseEvent != null)
                    {
                        if (baseEvent.eventTypeId == MouseMoveEvent.TypeId() ||
                            baseEvent.eventTypeId == MouseDownEvent.TypeId() ||
                            baseEvent.eventTypeId == MouseUpEvent.TypeId() ||
                            baseEvent.eventTypeId == WheelEvent.TypeId())
                        {
                            using (new EventDispatcherGate(dispatcher))
                            {
                                MouseEventsHelper.SendMouseOverMouseOut(previous, current, triggerMouseEvent, mousePos);
                                MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>(
                                    previous, current, triggerMouseEvent, mousePos);
                            }
                        }
                        else if (baseEvent.eventTypeId == MouseEnterWindowEvent.TypeId() ||
                                 baseEvent.eventTypeId == MouseLeaveWindowEvent.TypeId()
                                 )
                        {
                            using (new EventDispatcherGate(dispatcher))
                            {
                                PointerEventsHelper.SendOverOut(previous, current, null, mousePos, i);
                                PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>(
                                    previous, current, null, mousePos, i);

                                if (i == PointerId.mousePointerId)
                                {
                                    MouseEventsHelper.SendMouseOverMouseOut(previous, current, triggerMouseEvent, mousePos);
                                    MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>(
                                        previous, current, triggerMouseEvent, mousePos);
                                }
                            }
                        }
                        else if (baseEvent.eventTypeId == DragUpdatedEvent.TypeId() ||
                                 baseEvent.eventTypeId == DragExitedEvent.TypeId())
                        {
                            using (new EventDispatcherGate(dispatcher))
                            {
                                PointerEventsHelper.SendOverOut(previous, current, null, mousePos, i);
                                PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>(
                                    previous, current, null, mousePos, i);

                                MouseEventsHelper.SendMouseOverMouseOut(previous, current, triggerMouseEvent, mousePos);
                                MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>(
                                    previous, current, triggerMouseEvent, mousePos);
                                MouseEventsHelper.SendEnterLeave <DragLeaveEvent, DragEnterEvent>(
                                    previous, current, triggerMouseEvent, mousePos);
                            }
                        }
                    }

                    m_TriggerMouseEvent[i] = null;
                }
            }
        }