public bool GetMousePosOnThisArea(out Vector3 pos_world, out Vector3 pos_local, out Vector3 pos_matrix, out GridPos gp_matrix)
        {
            pos_world  = Vector3.zero;
            pos_local  = Vector3.zero;
            pos_matrix = Vector3.zero;
            gp_matrix  = GridPos.Zero;
            Ray ray      = DragProcessor.Camera.ScreenPointToRay(DragProcessor.CurrentMousePosition_Screen);
            int hitCount = Physics.RaycastNonAlloc(ray, cachedRaycastHits, 1000f, 1 << BoxCollider.gameObject.layer);

            if (hitCount > 0)
            {
                for (int i = 0; i < hitCount; i++)
                {
                    RaycastHit hit = cachedRaycastHits[i];
                    if (hit.collider != null && hit.collider == BoxCollider)
                    {
                        pos_world = hit.point;
                        Vector3 pos_local_absolute = UIInventory.UIInventoryPanel.ItemContainer.transform.InverseTransformPoint(pos_world);
                        Vector2 containerSize      = ((RectTransform)UIInventory.UIInventoryPanel.ItemContainer).rect.size;
                        pos_local  = new Vector3(pos_local_absolute.x + containerSize.x / 2f - UIInventory.GridSize / 2f, pos_local_absolute.y - containerSize.y / 2f + UIInventory.GridSize / 2f);
                        pos_matrix = new Vector3(pos_local_absolute.x + containerSize.x / 2f, -pos_local_absolute.y + containerSize.y / 2f);
                        Vector3 pos_matrix_round = new Vector3(pos_matrix.x - UIInventory.GridSize / 2f, pos_matrix.y - UIInventory.GridSize / 2f);
                        gp_matrix = GridPos.GetGridPosByPointXY(pos_matrix_round, UIInventory.GridSize);
                        return(true);
                    }
                }
            }

            pos_world = DragProcessor.Camera.ScreenToWorldPoint(new Vector3(DragProcessor.CurrentMousePosition_Screen.x, DragProcessor.CurrentMousePosition_Screen.y, UIInventory.CanvasDistance));
            return(false);
        }
        public bool GetMousePosOnThisArea(out Vector3 pos_world, out Vector3 pos_local, out Vector3 pos_matrix, out GridPos gp_matrix)
        {
            pos_world  = Vector3.zero;
            pos_local  = Vector3.zero;
            pos_matrix = Vector3.zero;
            gp_matrix  = GridPos.Zero;
            Ray ray = DragProcessor.Camera.ScreenPointToRay(DragProcessor.CurrentMousePosition_Screen);

            Physics.Raycast(ray, out RaycastHit hit, 1000f, 1 << BoxCollider.gameObject.layer);
            if (hit.collider)
            {
                if (hit.collider == BoxCollider)
                {
                    pos_world = hit.point;
                    Vector3 pos_local_absolute = Backpack.BackpackPanel.ItemContainer.transform.InverseTransformPoint(pos_world);
                    Vector2 containerSize      = ((RectTransform)Backpack.BackpackPanel.ItemContainer).rect.size;
                    pos_local  = new Vector3(pos_local_absolute.x + containerSize.x / 2f - Backpack.GridSize / 2f, pos_local_absolute.y - containerSize.y / 2f + Backpack.GridSize / 2f);
                    pos_matrix = new Vector3(pos_local_absolute.x + containerSize.x / 2f, -pos_local_absolute.y + containerSize.y / 2f);
                    Vector3 pos_matrix_round = new Vector3(pos_matrix.x - Backpack.GridSize / 2f, pos_matrix.y - Backpack.GridSize / 2f);
                    gp_matrix = GridPos.GetGridPosByPointXY(pos_matrix_round, Backpack.GridSize);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(false);
        }
Пример #3
0

        
Пример #4
0
        public void Draggable_OnMousePressed(DragArea dragArea, Vector3 diffFromStart, Vector3 deltaFromLastFrame)
        {
            if (dragArea.Equals(Backpack.DragArea))
            {
                if (Backpack.RotateItemKeyDownHandler != null && Backpack.RotateItemKeyDownHandler.Invoke())
                {
                    Rotate();
                }

                if (diffFromStart.magnitude <= Draggable_DragMinDistance)
                {
                    // stay
                }
                else
                {
                    Vector2  diffLocal       = RectTransform.parent.InverseTransformVector(diffFromStart);
                    Vector2  currentLocalPos = dragStartLocalPos + diffLocal;
                    GridPosR diff_world      = GridPos.GetGridPosByPointXY(diffLocal, Backpack.GridSize);
                    diff_world.orientation = InventoryItem.GridPos_Matrix.orientation;
                    GridPosR diff_matrix = Backpack.CoordinateTransformationHandler_FromPosToMatrixIndex(diff_world);
                    GridPosR gp_matrix   = dragStartGridPos_Matrix + diff_matrix;
                    gp_matrix.orientation = InventoryItem.GridPos_Matrix.orientation;
                    InventoryItem.SetGridPosition(gp_matrix);
                    RectTransform.anchoredPosition = currentLocalPos;
                }
            }
            else
            {
                if (Backpack.DragItemOutBackpackCallback != null)
                {
                    Backpack.BackpackPanel.BackpackItemVirtualOccupationRoot.Clear();
                    if (Backpack.DragItemOutBackpackCallback.Invoke(this))
                    {
                        InventoryItem.GridPos_Matrix = dragStartGridPos_Matrix;
                        Backpack.RemoveItem(InventoryItem, true);
                        PoolRecycle();
                    }
                }
            }
        }
Пример #5
0
        public void Draggable_OnMousePressed(DragAreaIndicator dragAreaIndicator, Vector3 diffFromStart, Vector3 deltaFromLastFrame)
        {
            void ResumePausedDrag()
            {
                InventoryItem.GridPos_Matrix = dragStartGridPos_Matrix;
                UIInventory.RemoveItem(InventoryItem, true);
                Destroy(gameObject);
                DragManager.Instance.ResumePausedDrag();
            }

            if (dragAreaIndicator == UIInventory.DragAreaIndicator)
            {
                if (UIInventory.RotateItemKeyDownHandler != null && UIInventory.RotateItemKeyDownHandler.Invoke())
                {
                    Rotate();
                }

                if (diffFromStart.magnitude > Draggable_DragMinDistance)
                {
                    Vector2  diffLocal       = RectTransform.parent.InverseTransformVector(diffFromStart);
                    Vector2  currentLocalPos = dragStartLocalPos + diffLocal;
                    GridPosR diff_world      = GridPos.GetGridPosByPointXY(diffLocal, UIInventory.GridSize);
                    diff_world.orientation = InventoryItem.GridPos_Matrix.orientation;
                    GridPosR diff_matrix = UIInventory.CoordinateTransformationHandler_FromPosToMatrixIndex(diff_world);
                    GridPosR gp_matrix   = dragStartGridPos_Matrix + diff_matrix;
                    gp_matrix.orientation        = InventoryItem.GridPos_Matrix.orientation;
                    InventoryItem.GridPos_Matrix = gp_matrix;
                    SetVirtualGridPos(InventoryItem.GridPos_World);
                    RectTransform.anchoredPosition = currentLocalPos;
                }
            }
            else
            {
                Vector2 diffLocal       = RectTransform.parent.InverseTransformVector(diffFromStart);
                Vector2 currentLocalPos = dragStartLocalPos + diffLocal;
                RectTransform.anchoredPosition = currentLocalPos;
                UIInventory.UIInventoryPanel.UIInventoryVirtualOccupationQuadRoot.Clear();
                if (dragAreaIndicator != null) // drag to other DragAreas
                {
                    if (DragManager.Instance.PausedDrag != null)
                    {
                        ResumePausedDrag();
                    }
                    else
                    {
                        // only when mouse move to available grid then generate previewItem
                        if (dragAreaIndicator is UIInventoryDragAreaIndicator uiDAI)
                        {
                            uiDAI.UIInventory.UIInventoryPanel.UIInventoryDragAreaIndicator.GetMousePosOnThisArea(out Vector3 pos_world, out Vector3 pos_local, out Vector3 pos_matrix, out GridPos gp_matrix);
                            GridPosR gpr = gp_matrix;
                            gpr.orientation = InventoryItem.GridPos_Matrix.orientation;
                            InventoryItem previewItem = new InventoryItem(InventoryItem.Clone().ItemContentInfo, uiDAI.UIInventory, gpr);
                            uiDAI.UIInventory.AddPreviewItem(previewItem);
                            UIInventoryItem uiInventoryItem = uiDAI.UIInventory.UIInventoryPanel.GetUIInventoryItem(previewItem.GUID);
                            DragManager.Instance.PauseDrag();
                            DragManager.Instance.CurrentDrag = uiInventoryItem.Draggable;
                            uiInventoryItem.Draggable.SetOnDrag(true, uiDAI.UIInventory.UIInventoryPanel.UIInventoryDragAreaIndicator.BoxCollider, UIInventory.DragProcessor);
                        }
                    }
                }
                else // drag to non-DragArea
                {
                    if (DragManager.Instance.PausedDrag != null)
                    {
                        ResumePausedDrag();
                    }
                }
            }
        }