示例#1
0
        /// <summary>
        /// Handle zoom of an ortographic camera.
        /// </summary>
        /// <param name="deltaMovementArgs">Delta movement arguments of the input.</param>
        private void ZoomOrtographic(IDeltaMovementInputArgs deltaMovementArgs)
        {
            if (deltaMovementArgs != null)
            {
                cameraToMove.orthographicSize -= deltaMovementArgs.DeltaMovement * Time.deltaTime * zoomSpeed;
            }

            cameraToMove.orthographicSize = cameraToMove.orthographicSize >= minOrtographicCameraZoom ? cameraToMove.orthographicSize : minOrtographicCameraZoom;
            cameraToMove.orthographicSize = cameraToMove.orthographicSize >= maxOrtographicCameraZoom ? maxOrtographicCameraZoom : cameraToMove.orthographicSize;
        }
示例#2
0
        /// <summary>
        /// Handle zoom of a perspective camera.
        /// </summary>
        /// <param name="deltaMovementArgs">Delta movement arguments of the input.</param>
        private void ZoomPerspective(IDeltaMovementInputArgs deltaMovementArgs)
        {
            if (deltaMovementArgs == null)
            {
                return;
            }

            var zoomedPosition = cameraToMove.transform.position;

            // Get expected position
            zoomedPosition -= Vector3.forward * -(deltaMovementArgs.DeltaMovement * Time.deltaTime * zoomSpeed);

            // Keep camera position in boundary
            zoomedPosition = zoomedPosition.z <= minPerspectiveCameraDistance ? zoomedPosition : Vector3.forward * minPerspectiveCameraDistance;
            zoomedPosition = zoomedPosition.z >= maxPerspectiveCameraDistance ? zoomedPosition : Vector3.forward * maxPerspectiveCameraDistance;

            cameraToMove.transform.position = zoomedPosition;
        }
 /// <summary>
 /// Gets direction of the positional input multiplied with the delta movement. Will be a zero vector most of the time, use overload with IVectorMovementInputArgs instead.
 /// </summary>
 /// <param name="args">Arguments of the input event.</param>
 /// <returns>Direction of the input.</returns>
 public static Vector2 GetDirection(IDeltaMovementInputArgs args) => (args.EndPos - args.StartPos) * args.DeltaMovement;
 /// <summary>
 /// Gets magnitude of the delta movement input.
 /// </summary>
 /// <param name="args">Arguments of the input event.</param>
 /// <returns>Magnitude of the input.</returns>
 public static float GetMagnitude(IDeltaMovementInputArgs args) => args.DeltaMovement;
 /// <summary>
 /// /// Gets start position added with the direction multiplied by the delta movement of the input.
 /// </summary>
 /// <param name="args">Arguments of the input event.</param>
 /// <returns>Focus point of the input.</returns>
 public static Vector2 GetFocusPoint(IDeltaMovementInputArgs args) => args.StartPos + GetDirection(args) * args.DeltaMovement;