public void Draggable_OnMousePressed(DragArea dragArea, Vector3 diffFromStart, Vector3 deltaFromLastFrame)
        {
            if (dragArea.Equals(DragAreaDefines.BattleInventory))
            {
                ReturnToBackpack(true, true);
                return;
            }

            if (dragArea.Equals(Inventory.DragArea))
            {
                if (Mecha && Mecha.MechaInfo.MechaCamp == MechaCamp.Player)
                {
                    if (Inventory.RotateItemKeyDownHandler != null && Inventory.RotateItemKeyDownHandler.Invoke())
                    {
                        MechaComponentInfo.InventoryItem.Rotate();
                    }

                    if (diffFromStart.magnitude <= Draggable_DragMinDistance)
                    {
                        //不动
                    }
                    else
                    {
                        Vector3  currentLocalPos = dragStartLocalPos + transform.parent.InverseTransformVector(diffFromStart);
                        GridPosR gp_world        = GridPos.GetGridPosByPointXZ(currentLocalPos, Inventory.GridSize);
                        gp_world.orientation = InventoryItem.GridPos_Matrix.orientation;
                        GridPosR gp_matrix = Inventory.CoordinateTransformationHandler_FromPosToMatrixIndex(gp_world);
                        MechaComponentInfo.InventoryItem.SetGridPosition(gp_matrix);
                    }
                }
            }
        }
    private bool GetPosOnThisArea(Vector2 screenPos, 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(screenPos);

        Physics.Raycast(ray, out RaycastHit hit, 1000f, LayerManager.Instance.LayerMask_DragAreas);
        if (hit.collider)
        {
            if (hit.collider == BoxCollider)
            {
                pos_world = hit.point;
                Vector3 pos_local_absolute = CityInventory.City.BuildingContainer.transform.InverseTransformPoint(pos_world);
                Vector3 containerSize      = new Vector3(CityInventory.Columns * CityInventory.GridSize, 0, CityInventory.Rows * CityInventory.GridSize);
                pos_local  = new Vector3(pos_local_absolute.x + containerSize.x / 2f - CityInventory.GridSize / 2f, 0, pos_local_absolute.z + containerSize.z / 2f - CityInventory.GridSize / 2f);
                pos_matrix = new Vector3(pos_local_absolute.x + containerSize.x / 2f, 0, pos_local_absolute.z + containerSize.z / 2f);
                Vector3 pos_matrix_round = new Vector3(pos_matrix.x - CityInventory.GridSize / 2f, 0, pos_matrix.z - CityInventory.GridSize / 2f);
                gp_matrix = GridPos.GetGridPosByPointXZ(pos_matrix_round, CityInventory.GridSize);
                return(true);
            }
            else
            {
                return(false);
            }
        }

        pos_world = CommonUtils.GetIntersectWithLineAndPlane(ray.origin, ray.direction, Vector3.up, transform.position);
        return(false);
    }
Exemple #3
0
        public void Update()
        {
            if (GameStateManager.Instance.GetState() == GameState.Building)
            {
                if (DragManager.Instance.CurrentDrag == null && DragManager.Instance.Current_DragArea.Equals(DragAreaDefines.MechaEditorArea))
                {
                    // Mouse Right button drag for rotate view
                    if (ControlManager.Instance.Building_MouseRight.Down)
                    {
                        onMouseDrag_Right = true;
                        if (GetMousePosOnThisArea(out Vector3 pos_world, out Vector3 _, out Vector3 _, out GridPos _))
                        {
                            mouseDownPos_Right = pos_world;
                        }
                    }

                    if (onMouseDrag_Right && ControlManager.Instance.Building_MouseRight.Pressed)
                    {
                        if (GetMousePosOnThisArea(out Vector3 pos_world, out Vector3 _, out Vector3 _, out GridPos _))
                        {
                            Vector3 startVec = mouseDownPos_Right - transform.position;
                            Vector3 endVec   = pos_world - transform.position;

                            float rotateAngle = Vector3.SignedAngle(startVec, endVec, transform.up);
                            if (Mathf.Abs(rotateAngle) > 3)
                            {
                                ClientBattleManager.Instance.PlayerMecha.transform.Rotate(0, rotateAngle, 0);
                                mouseDownPos_Right = pos_world;
                            }
                        }
                        else
                        {
                            onMouseDrag_Right  = false;
                            mouseDownPos_Right = Vector3.zero;
                        }
                    }

                    if (ControlManager.Instance.Building_MouseRight.Up)
                    {
                        onMouseDrag_Right  = false;
                        mouseDownPos_Right = Vector3.zero;
                    }

                    // Mouse Left button drag for move whole mecha
                    if (ControlManager.Instance.Building_MouseLeft.Down)
                    {
                        onMouseDrag_Left = true;
                        if (GetMousePosOnThisArea(out Vector3 pos, out Vector3 _, out Vector3 _, out GridPos _))
                        {
                            mouseDownPos_Left = pos;
                        }
                    }

                    if (onMouseDrag_Left && ControlManager.Instance.Building_MouseLeft.Pressed)
                    {
                        if (GetMousePosOnThisArea(out Vector3 pos, out Vector3 _, out Vector3 _, out GridPos _))
                        {
                            Vector3 delta          = pos - mouseDownPos_Left;
                            Vector3 delta_local    = ClientBattleManager.Instance.PlayerMecha.transform.InverseTransformVector(delta);
                            GridPos delta_local_GP = GridPos.GetGridPosByPointXZ(delta_local, 1);
                            if (delta_local_GP.x != 0 || delta_local_GP.z != 0)
                            {
                                ClientBattleManager.Instance.PlayerMecha.MechaInfo.MechaEditorInventory.MoveAllItemTogether(delta_local_GP);
                                mouseDownPos_Left = pos;
                            }
                        }
                        else
                        {
                            onMouseDrag_Left  = false;
                            mouseDownPos_Left = Vector3.zero;
                        }
                    }

                    if (ControlManager.Instance.Building_MouseLeft.Up)
                    {
                        onMouseDrag_Left  = false;
                        mouseDownPos_Left = Vector3.zero;
                    }
                }
            }
        }