예제 #1
0
        public void OnPointerUp(PointerEventData eventData)
        {
            if (!dragging)
            {
                return;
            }
            Ray ray = Camera.main.ScreenPointToRay(eventData.position);

            List <RaycastResult> res = new List <RaycastResult>();

            EventSystem.current.RaycastAll(eventData, res);

            dragReleased?.Invoke(this, eventData.position);
            DragReleased?.Invoke(this, eventData.position);

            GetEventCamera();

            if (eventCamera != null)
            {
                ray = eventCamera.ScreenPointToRay(Input.mousePosition);
                RaycastHit[]   hits   = Physics.RaycastAll(ray, float.MaxValue, dragMask);
                RaycastHit2D[] hits2D = Physics2D.GetRayIntersectionAll(ray, float.MaxValue, dragMask);

                IEnumerable <GameObject> intersectedObjects =
                    hits.Select(h => h.collider.gameObject)
                    .Union(
                        hits2D.Select(h2d => h2d.collider.gameObject))
                    .Union(
                        res.Select(resHit => resHit.gameObject));


                foreach (GameObject go in intersectedObjects)
                {
                    draggedToWorldSpaceObject?.Invoke(this, go);
                    DraggedToWorldSpaceObject?.Invoke(this, go);
                    foreach (IInventorySlotInteractable slotInteractable in go.GetComponents <IInventorySlotInteractable>())
                    {
                        slotInteractable.InventorySlotDroppedOnObject(this);
                    }
                }
            }


            dragObject.SetActive(false);
            dragging = false;
        }
예제 #2
0
        private void TabberItem_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed && dragTabAndWindow)
            {
                Window        currentWindow = Window.GetWindow(this);
                TabberControl tabberControl = (TabberControl)Parent;
                if (!((currentWindow as ContentWindow) == null &&
                      tabberControl.Items.Count < 2 &&
                      tabberControl.Pinned))
                {
                    Point innerMousePosition = Mouse.GetPosition(this);

                    if (moveEnter)
                    {
                        if (tabberControl.TabStripPlacement == Dock.Top || tabberControl.TabStripPlacement == Dock.Bottom)
                        {
                            #region Drag Section
                            if (((innerMousePosition.Y <= 0 || innerMousePosition.Y >= ActualHeight) &&
                                 (innerMousePosition.X > 0 && innerMousePosition.X < ActualWidth)) ||
                                (tabberControl.Items[0].Equals(this) && innerMousePosition.X <= 0) ||
                                (tabberControl.Items[tabberControl.Items.Count - 1].Equals(this) && innerMousePosition.X >= ActualWidth))
                            {
                                if (IsMouseCaptured)
                                {
                                    Mouse.Capture(null);
                                }

                                DragPressed?.Invoke(this, new EventArgs());
                                Point dragPosition = this.PointToScreen(innerMousePosition);
                                Pin    = false;
                                window = new ContentWindow(
                                    this,
                                    new Rect(
                                        dragPosition.X + (-ActualWidth / 2),
                                        dragPosition.Y + (-ActualHeight / 2),
                                        currentWindow.ActualWidth,
                                        currentWindow.ActualHeight),
                                    true);
                                dragTabAndWindow = false;
                                inDragMove       = true;
                                window.DragMove();
                                DragReleased?.Invoke(this, new EventArgs());
                            }
                            #endregion
                            #region Swap Section
                            else if (!tabberControl.Items[0].Equals(this) && innerMousePosition.X <= 0)
                            {
                                int        index    = tabberControl.Items.IndexOf(this);
                                TabberItem swapItem = (TabberItem)tabberControl.Items[index - 1];
                                if (swapItem.Pin == Pin)
                                {
                                    tabberControl.Items.Remove(swapItem);
                                    tabberControl.Items.Insert(index, swapItem);
                                }
                            }
                            else if (!tabberControl.Items[tabberControl.Items.Count - 1].Equals(this) && innerMousePosition.X >= ActualWidth)
                            {
                                int        index    = tabberControl.Items.IndexOf(this);
                                TabberItem swapItem = (TabberItem)tabberControl.Items[index + 1];
                                if (swapItem.Pin == Pin)
                                {
                                    tabberControl.Items.Remove(swapItem);
                                    tabberControl.Items.Insert(index, swapItem);
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            #region Drag Section
                            if (((innerMousePosition.X <= 0 || innerMousePosition.X >= ActualWidth) &&
                                 (innerMousePosition.Y > 0 && innerMousePosition.Y < ActualHeight)) ||
                                (tabberControl.Items[0].Equals(this) && innerMousePosition.Y <= 0) ||
                                (tabberControl.Items[tabberControl.Items.Count - 1].Equals(this) && innerMousePosition.Y >= ActualHeight))
                            {
                                if (IsMouseCaptured)
                                {
                                    Mouse.Capture(null);
                                }

                                DragPressed?.Invoke(this, new EventArgs());
                                Point dragPosition = this.PointToScreen(innerMousePosition);
                                Pin    = false;
                                window = new ContentWindow(
                                    this,
                                    new Rect(
                                        dragPosition.X + (-ActualWidth / 2),
                                        dragPosition.Y + (-ActualHeight / 2),
                                        currentWindow.ActualWidth,
                                        currentWindow.ActualHeight),
                                    true);
                                dragTabAndWindow = false;
                                inDragMove       = true;
                                window.DragMove();
                                DragReleased?.Invoke(this, new EventArgs());
                            }
                            #endregion
                            #region Swap Section
                            else if (!tabberControl.Items[0].Equals(this) && innerMousePosition.Y <= 0)
                            {
                                int        index    = tabberControl.Items.IndexOf(this);
                                TabberItem swapItem = (TabberItem)tabberControl.Items[index - 1];
                                if (swapItem.Pin == Pin)
                                {
                                    tabberControl.Items.Remove(swapItem);
                                    tabberControl.Items.Insert(index, swapItem);
                                }
                            }
                            else if (!tabberControl.Items[tabberControl.Items.Count - 1].Equals(this) && innerMousePosition.Y >= ActualHeight)
                            {
                                int        index    = tabberControl.Items.IndexOf(this);
                                TabberItem swapItem = (TabberItem)tabberControl.Items[index + 1];
                                if (swapItem.Pin == Pin)
                                {
                                    tabberControl.Items.Remove(swapItem);
                                    tabberControl.Items.Insert(index, swapItem);
                                }
                            }
                            #endregion
                        }
                    }
                    moveEnter = TabItemLocalRect().Contains(Mouse.GetPosition(this));
                }
            }
            else if (e.LeftButton == MouseButtonState.Released)
            {
                if (IsMouseCaptured && !inDragMove)
                {
                    Mouse.Capture(null);
                }
            }
        }