private Vector3 ClampDragPosition(MobileTouchPickable draggedPickable, Vector3 position) { var draggedTransform = draggedPickable.PickableTransform; if (mobileTouchCam.CameraAxes == CameraPlaneAxes.XY_2D_SIDESCROLL) { if (snapAngle == SnapAngle.Diagonal_45_Degrees) { RotateVector2(ref position.x, ref position.y, -snapAngleDiagonal); } position.x = GetPositionXSnapped(position.x, draggedPickable.LocalSnapOffset.x + snapOffset.x); position.y = GetPositionYSnapped(position.y, draggedPickable.LocalSnapOffset.y + snapOffset.y); position.z = draggedTransform.position.z; if (snapAngle == SnapAngle.Diagonal_45_Degrees) { RotateVector2(ref position.x, ref position.y, snapAngleDiagonal); } } else { if (snapAngle == SnapAngle.Diagonal_45_Degrees) { RotateVector2(ref position.x, ref position.z, -snapAngleDiagonal); } position.x = GetPositionXSnapped(position.x, draggedPickable.LocalSnapOffset.x + snapOffset.x); position.y = draggedTransform.position.y; position.z = GetPositionYSnapped(position.z, draggedPickable.LocalSnapOffset.y + snapOffset.y); if (snapAngle == SnapAngle.Diagonal_45_Degrees) { RotateVector2(ref position.x, ref position.z, snapAngleDiagonal); } } return(position); }
private void InputControllerOnFingerDown(Vector3 fingerDownPos) { CurrentlyDraggedPickable = null; bool isDragStartedOnSelection = false; //try{ isDragStartedOnSelection = SelectedCollider != null && GetClosestColliderAtScreenPoint(fingerDownPos) == SelectedCollider && SelectedCollider.GetComponent<MobileTouchPickable>().checkMove; // } catch { } try { isDragStartedOnSelection = SelectedCollider != null && GetClosestColliderAtScreenPoint(fingerDownPos) == SelectedCollider; } catch { } if (isDragStartedOnSelection == true) { MobileTouchPickable mobileTouchPickable = SelectedCollider.GetComponent <MobileTouchPickable>(); if (mobileTouchPickable != null) { mobileTouchCam.OnDragSceneObject(); //Lock camera movement. CurrentlyDraggedPickable = mobileTouchPickable; currentlyDraggedTransformPosition = CurrentlyDraggedTransform.position; DraggedTransformOffset = Vector3.zero; if (mobileTouchCam.Cam.orthographic == true && snapToGrid == false) { DraggedTransformOffset = CurrentlyDraggedTransform.position - ComputeDragPositionWorld(fingerDownPos); } } } }
private void Select(Component colliderComponent, bool isDoubleClick, bool isLongTap) { MobileTouchPickable mobileTouchPickable = colliderComponent.GetComponent <MobileTouchPickable>(); if (mobileTouchPickable != null) { if (SelectedColliders.Contains(colliderComponent) == false) { SelectedColliders.Add(colliderComponent); } } OnSelectedColliderChanged(SelectionAction.Select, mobileTouchPickable); OnSelectedColliderChangedExtended(SelectionAction.Select, mobileTouchPickable, isDoubleClick, isLongTap); }
private void OnSelectedColliderChanged(SelectionAction selectionAction, MobileTouchPickable mobileTouchPickable) { if (mobileTouchPickable != null) { if (selectionAction == SelectionAction.Select) { InvokeTransformActionSafe(OnPickableTransformSelected, mobileTouchPickable.PickableTransform); } else if (selectionAction == SelectionAction.Deselect) { InvokeTransformActionSafe(OnPickableTransformDeselected, mobileTouchPickable.PickableTransform); } } }
private void RequestDragPickable(Component colliderComponent, Vector2 fingerDownPos, Vector3 intersectionPoint) { if (requireLongTapForMove == true && isSelectedViaLongTap == false) { return; } CurrentlyDraggedPickable = null; bool isDragStartedOnSelection = colliderComponent != null && SelectedColliders.Contains(colliderComponent); if (isDragStartedOnSelection == true) { MobileTouchPickable mobileTouchPickable = colliderComponent.GetComponent <MobileTouchPickable>(); if (mobileTouchPickable != null) { mobileTouchCam.OnDragSceneObject(); //Lock camera movement. CurrentlyDraggedPickable = mobileTouchPickable; currentlyDraggedTransformPosition = CurrentlyDraggedTransform.position; invokeMoveStartedOnDrag = true; currentDragStartPos = CurrentlyDraggedTransform.position; selectionPositionOffsets.Clear(); foreach (Component selectionComponent in SelectedColliders) { selectionPositionOffsets.Add(selectionComponent, currentDragStartPos - selectionComponent.transform.position); } draggedTransformOffset = Vector3.zero; draggedTransformHeightOffset = Vector3.zero; draggedItemCustomOffset = Vector3.zero; //Find offset of item transform relative to ground. Vector3 groundPosCenter = Vector3.zero; Ray groundScanRayCenter = new Ray(CurrentlyDraggedTransform.position, -mobileTouchCam.RefPlane.normal); bool rayHitSuccess = mobileTouchCam.RaycastGround(groundScanRayCenter, out groundPosCenter); if (rayHitSuccess == true) { draggedTransformHeightOffset = CurrentlyDraggedTransform.position - groundPosCenter; } else { groundPosCenter = CurrentlyDraggedTransform.position; } draggedTransformOffset = groundPosCenter - intersectionPoint; itemInitialDragOffsetWorld = (ComputeDragPosition(fingerDownPos, SnapToGrid) - CurrentlyDraggedTransform.position); } } }
private void InputControllerOnDragStart(Vector3 clickPosition, bool isLongTap) { if (isLongTap == true && touchInputController.LongTapStartsDrag == true) { Vector3 intersectionPoint; Component newCollider = GetClosestColliderAtScreenPoint(clickPosition, out intersectionPoint); if (newCollider != null) { MobileTouchPickable newPickable = newCollider.GetComponent <MobileTouchPickable>(); if (newPickable != null) { SelectColliderInternal(newCollider, false, isLongTap); RequestDragPickable(clickPosition); } } } }
private void RequestDragPickable(Component colliderComponent, Vector2 fingerDownPos, Vector3?intersectionPoint) { CurrentlyDraggedPickable = null; bool isDragStartedOnSelection = SelectedCollider != null && colliderComponent == SelectedCollider; if (isDragStartedOnSelection == true) { MobileTouchPickable mobileTouchPickable = SelectedCollider.GetComponent <MobileTouchPickable>(); if (mobileTouchPickable != null) { mobileTouchCam.OnDragSceneObject(); //Lock camera movement. CurrentlyDraggedPickable = mobileTouchPickable; currentlyDraggedTransformPosition = CurrentlyDraggedTransform.position; invokeMoveStartedOnDrag = true; currentDragStartPos = CurrentlyDraggedTransform.position; draggedTransformOffset = Vector3.zero; draggedTransformHeightOffset = Vector3.zero; draggedItemCustomOffset = Vector3.zero; if (intersectionPoint != null && intersectionPoint.HasValue == true) { //Find offset of item transform relative to ground. Vector3 groundPosCenter = Vector3.zero; Ray groundScanRayCenter = new Ray(CurrentlyDraggedTransform.position, -mobileTouchCam.RefPlane.normal); bool rayHitSuccess = mobileTouchCam.RaycastGround(groundScanRayCenter, out groundPosCenter); if (rayHitSuccess == true) { draggedTransformHeightOffset = CurrentlyDraggedTransform.position - groundPosCenter; } else { groundPosCenter = CurrentlyDraggedTransform.position; } draggedTransformOffset = groundPosCenter - intersectionPoint.Value; } itemInitialDragOffsetWorld = (ComputeDragPosition(fingerDownPos, SnapToGrid) - CurrentlyDraggedTransform.position); } } }
private void OnSelectedColliderChangedExtended(SelectionAction selectionAction, MobileTouchPickable mobileTouchPickable, bool isDoubleClick, bool isLongTap) { if (mobileTouchPickable != null) { if (selectionAction == SelectionAction.Select) { PickableSelectedData pickableSelectedData = new PickableSelectedData() { SelectedTransform = mobileTouchPickable.PickableTransform, IsDoubleClick = isDoubleClick, IsLongTap = isLongTap }; InvokeGenericActionSafe(OnPickableTransformSelectedExtended, pickableSelectedData); } } }