Пример #1
0
 protected override void OnMouseDown(UnityEngine.UIElements.MouseDownEvent e)
 {
     m_Active = true;
     target.CaptureMouse();
     m_ClickOrigin = GetImageCoord(Image, e.localMousePosition);
     Vector2Int[] coords = Flood(m_ClickOrigin);
     uPixel.DrawBuffer(coords);
 }
Пример #2
0
 protected override void OnMouseDown(UnityEngine.UIElements.MouseDownEvent e)
 {
     if (m_Active)
     {
         e.StopImmediatePropagation();
         return;
     }
     if (CanStartManipulation(e))
     {
         m_Active = true;
         target.CaptureMouse();
         m_ClickOrigin = GetImageCoord(Image, e.localMousePosition);
         Vector2Int[] coords = GetTargetCoords(m_ClickOrigin);
         uPixel.DrawBuffer(coords);
     }
     e.StopPropagation();
 }
Пример #3
0
        public void ReplayEvents(List <EventDebuggerEventRecord> eventBases)
        {
            if (eventBases == null)
            {
                return;
            }

            foreach (var eventBase in eventBases)
            {
                Event newEvent = new Event
                {
                    button        = eventBase.button,
                    clickCount    = eventBase.clickCount,
                    modifiers     = eventBase.modifiers,
                    mousePosition = eventBase.mousePosition,
                };

                if (eventBase.eventTypeId == MouseMoveEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseMove;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseMove), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseDownEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseDown;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseDown), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseUpEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseUp;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseUp), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == ContextClickEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.ContextClick;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ContextClick), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseEnterWindowEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseEnterWindow;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseEnterWindow), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseLeaveWindowEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseLeaveWindow;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseLeaveWindow), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == WheelEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type  = EventType.ScrollWheel;
                    newEvent.delta = eventBase.delta;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ScrollWheel), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == KeyDownEvent.TypeId())
                {
                    newEvent.type      = EventType.KeyDown;
                    newEvent.character = eventBase.character;
                    newEvent.keyCode   = eventBase.keyCode;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.KeyDown), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == KeyUpEvent.TypeId())
                {
                    newEvent.type      = EventType.KeyUp;
                    newEvent.character = eventBase.character;
                    newEvent.keyCode   = eventBase.keyCode;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.KeyUp), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == DragUpdatedEvent.TypeId())
                {
                    newEvent.type = EventType.DragUpdated;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.DragUpdated), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == DragPerformEvent.TypeId())
                {
                    newEvent.type = EventType.DragPerform;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.DragPerform), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == DragExitedEvent.TypeId())
                {
                    newEvent.type = EventType.DragExited;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.DragExited), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == ValidateCommandEvent.TypeId())
                {
                    newEvent.type        = EventType.ValidateCommand;
                    newEvent.commandName = eventBase.commandName;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ValidateCommand), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == ExecuteCommandEvent.TypeId())
                {
                    newEvent.type        = EventType.ExecuteCommand;
                    newEvent.commandName = eventBase.commandName;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ExecuteCommand), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == IMGUIEvent.TypeId())
                {
                    Debug.Log("Skipped IMGUI event (" + eventBase.eventBaseName + "): " + eventBase);
                    continue;
                }
                else
                {
                    Debug.Log("Skipped event (" + eventBase.eventBaseName + "): " + eventBase);
                    continue;
                }

                Debug.Log("Replayed event (" + eventBase.eventBaseName + "): " + newEvent);
            }
        }
Пример #4
0
 protected override void OnMouseDown(UnityEngine.UIElements.MouseDownEvent e)
 {
     m_ClickOrigin = GetImageCoord(Image, e.localMousePosition);
     uPixel.SetPaletteIndex(uPixel.GetPaletteIndex(m_ClickOrigin));
 }
Пример #5
0
        private void OnClick(MouseDownEvent evt)
        {
            if (!HasValidDataAndBindings())
            {
                return;
            }

            if (evt.button != (int)MouseButton.LeftMouse)
            {
                return;
            }

            var clickedIndex = (int)(evt.localMousePosition.y / itemHeight);

            if (clickedIndex > m_ItemsSource.Count - 1)
            {
                return;
            }

            var clickedItem   = m_ItemsSource[clickedIndex];
            var clickedItemId = GetIdFromIndex(clickedIndex);

            switch (evt.clickCount)
            {
            case 1:
                if (selectionType == SelectionType.None)
                {
                    return;
                }

                if (selectionType == SelectionType.Multiple && evt.actionKey)
                {
                    m_RangeSelectionOrigin = clickedIndex;

                    // Add/remove single clicked element
                    if (m_SelectedIds.Contains(clickedItemId))
                    {
                        RemoveFromSelection(clickedIndex);
                    }
                    else
                    {
                        AddToSelection(clickedIndex);
                    }
                }
                else if (selectionType == SelectionType.Multiple && evt.shiftKey)
                {
                    if (m_RangeSelectionOrigin == -1)
                    {
                        m_RangeSelectionOrigin = clickedIndex;
                        SetSelection(clickedIndex);
                    }
                    else
                    {
                        foreach (var recycledItem in m_Pool)
                        {
                            recycledItem.SetSelected(false);
                        }
                        m_SelectedIds.Clear();
                        m_SelectedIndices.Clear();
                        m_SelectedItems.Clear();

                        // Add range
                        if (clickedIndex < m_RangeSelectionOrigin)
                        {
                            for (int i = clickedIndex; i <= m_RangeSelectionOrigin; i++)
                            {
                                AddToSelection(i);
                            }
                        }
                        else
                        {
                            for (int i = m_RangeSelectionOrigin; i <= clickedIndex; i++)
                            {
                                AddToSelection(i);
                            }
                        }
                    }
                }
                else     // single
                {
                    m_RangeSelectionOrigin = clickedIndex;
                    SetSelection(clickedIndex);
                }
                break;

            case 2:
                if (onItemChosen == null)
                {
                    return;
                }

                onItemChosen.Invoke(clickedItem);
                break;
            }
        }