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); } } } }
public void Draggable_OnMouseUp(DragArea dragArea, Vector3 diffFromStart, Vector3 deltaFromLastFrame) { Backpack.BackpackPanel.BackpackItemVirtualOccupationRoot.Clear(); if (dragArea.Equals(Backpack.DragArea)) { if (Backpack.CheckSpaceAvailable(dragStartOccupiedPositions_Matrix)) { Backpack.ResetGrids(dragStartOccupiedPositions_Matrix); } else { // indicates that this is dragged in from outside, and conflict at the first position with another item. } if (!Backpack.CheckSpaceAvailable(InventoryItem.OccupiedGridPositions_Matrix)) { InventoryItem.GridPos_Matrix = dragStartGridPos_Matrix; } if (!Backpack.CheckSpaceAvailable(InventoryItem.OccupiedGridPositions_Matrix)) { if (Backpack.FindSpaceToPutItem(InventoryItem)) { } else { Debug.LogError("No space in bag but suc drag in"); } } Backpack.PutDownItem(InventoryItem); RefreshView(); } }
public void Draggable_OnMouseUp(DragArea dragArea, Vector3 diffFromStart, Vector3 deltaFromLastFrame) { if (IsRecycled) { return; } if (dragArea.Equals(DragAreaDefines.BattleInventory)) { if (!isReturningToBackpack) { bool suc = ReturnToBackpack(false, false); if (!suc) { //DragManager.Instance.CurrentDrag.ResetToOriginalPositionRotation(); } } return; } if (dragArea.Equals(DragAreaDefines.MechaEditorArea)) { return; } if (dragArea.Equals(BiangStudio.DragHover.DragAreaDefines.None)) { bool suc = ReturnToBackpack(false, false); if (!suc) { //DragManager.Instance.CurrentDrag.ResetToOriginalPositionRotation(); } return; } }
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(); } } } }