private void UpdateDuringNoAction(TileControl currentTileUnderMouse)
 {
     if (input.GetMouseButtonDown(2) || (input.GetMouseButtonDown(0) && input.GetMouseButton(1)) || (input.GetMouseButtonDown(1) && input.GetMouseButton(0)))
     {
         StartDoublePressing(currentTileUnderMouse);
         return;
     }
     if (input.GetMouseButtonDown(0) && currentTileUnderMouse != null && currentTileUnderMouse.tile.isClickable)
     {
         StartPressing(currentTileUnderMouse);
         return;
     }
     if (input.GetMouseButtonDown(1) && currentTileUnderMouse != null)
     {
         mineField.ToggleFlag(currentTileUnderMouse.tile);
     }
 }
Example #2
0
    private void Update()
    {
        if (Time.unscaledDeltaTime != 0f)
        {
            float mouseScrollAmount = Mathf.Clamp(input.mouseScrollDelta.y, -mouseScrollMaxTickPerFrame, mouseScrollMaxTickPerFrame);

            if (allowRotating && input.GetMouseButtonDown(0))
            {
                SetMode(Mode.Rotation);
                center.Hide();
            }
            else if (allowPanning && input.GetMouseButtonDown(1))
            {
                SetMode(Mode.Panning);
                center.Show();
            }
            else if (allowRotating && input.GetMouseButton(0) && mode == Mode.Rotation)
            {
                // Rotate the camera.
                Vector3    v1       = new Vector3(prevMousePos.x - Screen.width / 2, prevMousePos.y - Screen.height / 2, -mouseRotationControlDistance);
                Vector3    v2       = new Vector3(input.mousePosition.x - Screen.width / 2, input.mousePosition.y - Screen.height / 2, -mouseRotationControlDistance);
                Quaternion rotation = Quaternion.Inverse(Quaternion.FromToRotation(v1, v2));
                rotation.ToAngleAxis(out float angle, out Vector3 axis);
                rotation       = Quaternion.AngleAxis(angle * mouseRotationFactor, axis);
                targetRotation = targetRotation * rotation;
            }
            else if (allowPanning && input.GetMouseButton(1) && mode == Mode.Panning)
            {
                // Pan the camera.
                float   distancePixelRatio = (cam.ScreenToWorldPoint(new Vector3(1, 0, targetDistance)) - cam.ScreenToWorldPoint(new Vector3(0, 0, targetDistance))).magnitude * mousePanningFactor;
                Vector3 move = new Vector3((prevMousePos.x - input.mousePosition.x) * distancePixelRatio,
                                           (prevMousePos.y - input.mousePosition.y) * distancePixelRatio,
                                           mouseScrollAmount * targetDistance * mouseScrollMovingFactor);
                targetOffset += targetRotation * move;
            }
            else
            {
                SetMode(Mode.NoAction);
                center.Hide();
            }

            if (allowZooming && mode != Mode.Panning)
            {
                // Zoom the camera.
                targetDistance *= Mathf.Exp(-mouseScrollAmount * mouseScrollZoomingFactor);
            }
            if (allowPanning && input.GetMouseButtonDown(2))
            {
                // Reset the camera center position.
                targetOffset = Vector3.zero;
            }

            // Smooth transition
            transform.rotation             = Quaternion.Slerp(targetRotation, transform.rotation, Mathf.Exp(-Time.unscaledDeltaTime / smoothT));
            distance                       = Mathf.Lerp(targetDistance, distance, Mathf.Exp(-Time.unscaledDeltaTime / smoothT));
            offset                         = Vector3.Lerp(targetOffset, offset, Mathf.Exp(-Time.unscaledDeltaTime / smoothT));
            transform.position             = target.transform.position + distance * (transform.rotation * Vector3.back) + offset;
            center.transform.localPosition = new Vector3(0, 0, distance);
            if (adaptiveCrosshairSize)
            {
                center.transform.localScale = Vector3.one * distance * adaptiveCrosshairSizeMultiplier;
            }

            prevMousePos = input.mousePosition;
        }
    }