示例#1
0
        protected void UpdateScreenSize(float smoothness)
        {
            _targetCamSizeSmoothed = Mathf.SmoothDamp(_targetCamSizeSmoothed, _targetCamSize, ref _velocity, smoothness);

            ProCamera2D.UpdateScreenSize(_targetCamSizeSmoothed);

            _targetCamSizeSmoothed = _gameCameraSize;
        }
示例#2
0
        /// <summary>
        /// Resizes the camera to a pixel perfect size
        /// </summary>
        public void ResizeCameraToPixelPerfect()
        {
            _viewportScale = CalculateViewportScale();

            _pixelStep = CalculatePixelStep(_viewportScale);

            var newSize = ((ProCamera2D.GameCamera.pixelHeight * .5f) * (1f / PixelsPerUnit)) / (Zoom * _viewportScale);

            ProCamera2D.UpdateScreenSize(newSize);
        }
示例#3
0
        protected void UpdateScreenSize()
        {
            _previousCamSize       = _targetCamSizeSmoothed;
            _targetCamSizeSmoothed = Mathf.SmoothDamp(_targetCamSizeSmoothed, _targetCamSize, ref _velocity, _targetCamSize < _targetCamSizeSmoothed ? ZoomInSmoothness : ZoomOutSmoothness);

            if (Math.Abs(_targetCamSizeSmoothed - _previousCamSize) > .0001f)
            {
                ProCamera2D.UpdateScreenSize(_targetCamSizeSmoothed);
                _targetCamSizeSmoothed = _gameCameraSize;
            }
        }
        void LimitSizeAndPositionToNumericBoundaries()
        {
            // Set new size if outside boundaries
            IsCameraSizeBounded = false;
            var cameraBounds = new Vector2(RightBoundary - LeftBoundary, TopBoundary - BottomBoundary);

            if (UseRightBoundary && UseLeftBoundary && ProCamera2D.ScreenSizeInWorldCoordinates.x > cameraBounds.x)
            {
                ProCamera2D.UpdateScreenSize(cameraBounds.x / ProCamera2D.GameCamera.aspect / 2);
                IsCameraSizeBounded = true;
            }

            if (UseTopBoundary && UseBottomBoundary && ProCamera2D.ScreenSizeInWorldCoordinates.y > cameraBounds.y)
            {
                ProCamera2D.UpdateScreenSize(cameraBounds.y / 2);
                IsCameraSizeBounded = true;
            }

            // Check movement in the horizontal dir
            IsCameraPositionHorizontallyBounded = false;
            IsCameraPositionVerticallyBounded   = false;
            var newPosH = Vector3H(_transform.localPosition);

            if (UseLeftBoundary && newPosH - ProCamera2D.ScreenSizeInWorldCoordinates.x / 2 < LeftBoundary)
            {
                newPosH = LeftBoundary + ProCamera2D.ScreenSizeInWorldCoordinates.x / 2;
                IsCameraPositionHorizontallyBounded = true;
            }
            else if (UseRightBoundary && newPosH + ProCamera2D.ScreenSizeInWorldCoordinates.x / 2 > RightBoundary)
            {
                newPosH = RightBoundary - ProCamera2D.ScreenSizeInWorldCoordinates.x / 2;
                IsCameraPositionHorizontallyBounded = true;
            }

            // Check movement in the vertical dir
            var newPosV = Vector3V(_transform.localPosition);

            if (UseBottomBoundary && newPosV - ProCamera2D.ScreenSizeInWorldCoordinates.y / 2 < BottomBoundary)
            {
                newPosV = BottomBoundary + ProCamera2D.ScreenSizeInWorldCoordinates.y / 2;
                IsCameraPositionVerticallyBounded = true;
            }
            else if (UseTopBoundary && newPosV + ProCamera2D.ScreenSizeInWorldCoordinates.y / 2 > TopBoundary)
            {
                newPosV = TopBoundary - ProCamera2D.ScreenSizeInWorldCoordinates.y / 2;
                IsCameraPositionVerticallyBounded = true;
            }

            // Set to the new position
            if (IsCameraPositionHorizontallyBounded || IsCameraPositionVerticallyBounded)
            {
                ProCamera2D.CameraPosition = VectorHVD(newPosH, newPosV, Vector3D(_transform.localPosition));
            }
        }
        void LimitSizeToNumericBoundaries()
        {
            // Set new size if outside boundaries
            var cameraBounds = new Vector2(RightBoundary - LeftBoundary, TopBoundary - BottomBoundary);

            if (UseRightBoundary && UseLeftBoundary && ProCamera2D.ScreenSizeInWorldCoordinates.x > cameraBounds.x)
            {
                ProCamera2D.UpdateScreenSize(cameraBounds.x / ProCamera2D.GameCamera.aspect / 2);
            }

            if (UseTopBoundary && UseBottomBoundary && ProCamera2D.ScreenSizeInWorldCoordinates.y > cameraBounds.y)
            {
                ProCamera2D.UpdateScreenSize(cameraBounds.y / 2);
            }
        }
        void Override()
        {
            OverridenPosition          = ProCamera2D.CameraPosition;
            ProCamera2D.CameraPosition = OverridePosition;

            if (UseNumericBoundaries)
            {
                LimitPositionToNumericBoundaries();
            }

            if (OverrideSize > 0)
            {
                OverridenSize = ProCamera2D.GameCameraSize;
                ProCamera2D.UpdateScreenSize(OverrideSize);

                if (UseNumericBoundaries)
                {
                    LimitSizeToNumericBoundaries();
                }
            }
        }
        IEnumerator Transition()
        {
            if (!UseTopBoundary && !UseBottomBoundary && !UseLeftBoundary && !UseRightBoundary)
            {
                NumericBoundaries.UseNumericBoundaries = false;
                yield break;
            }

            // Avoid unnecessary transitions
            var skip = true;

            if (UseTopBoundary && (NumericBoundaries.TopBoundary != TopBoundary || !NumericBoundaries.UseTopBoundary))
            {
                skip = false;
            }
            if (UseBottomBoundary && (NumericBoundaries.BottomBoundary != BottomBoundary || !NumericBoundaries.UseBottomBoundary))
            {
                skip = false;
            }
            if (UseLeftBoundary && (NumericBoundaries.LeftBoundary != LeftBoundary || !NumericBoundaries.UseLeftBoundary))
            {
                skip = false;
            }
            if (UseRightBoundary && (NumericBoundaries.RightBoundary != RightBoundary || !NumericBoundaries.UseRightBoundary))
            {
                skip = false;
            }
            if (skip)
            {
                yield break;
            }

            NumericBoundaries.UseNumericBoundaries = true;

            GetTargetBoundaries();

            _boundsAnim.UseTopBoundary    = UseTopBoundary;
            _boundsAnim.TopBoundary       = _targetTopBoundary;
            _boundsAnim.UseBottomBoundary = UseBottomBoundary;
            _boundsAnim.BottomBoundary    = _targetBottomBoundary;
            _boundsAnim.UseLeftBoundary   = UseLeftBoundary;
            _boundsAnim.LeftBoundary      = _targetLeftBoundary;
            _boundsAnim.UseRightBoundary  = UseRightBoundary;
            _boundsAnim.RightBoundary     = _targetRightBoundary;

            _boundsAnim.TransitionDuration = TransitionDuration;
            _boundsAnim.TransitionEaseType = TransitionEaseType;

            // Zoom
            if (ChangeZoom && _initialCamSize / TargetZoom != ProCamera2D.ScreenSizeInWorldCoordinates.y * .5f)
            {
                ProCamera2D.UpdateScreenSize(_initialCamSize / TargetZoom, ZoomSmoothness, TransitionEaseType);
            }


            // Move camera "manually"
            if (_boundsAnim.GetAnimsCount() > 1)
            {
                if (NumericBoundaries.MoveCameraToTargetRoutine != null)
                {
                    NumericBoundaries.StopCoroutine(NumericBoundaries.MoveCameraToTargetRoutine);
                }

                NumericBoundaries.MoveCameraToTargetRoutine = NumericBoundaries.StartCoroutine(MoveCameraToTarget());
            }

            // Start bounds animation
            yield return(new WaitForEndOfFrame());

            _boundsAnim.Transition();
        }
示例#8
0
        protected void UpdateScreenSize(float smoothness)
        {
            _targetCamSizeSmoothed = Mathf.SmoothDamp(_targetCamSizeSmoothed, _targetCamSize, ref _zoomVelocity, smoothness, float.MaxValue, ProCamera2D.DeltaTime);

            ProCamera2D.UpdateScreenSize(_targetCamSizeSmoothed);
        }
示例#9
0
        void Transition()
        {
            if (!UseTopBoundary && !UseBottomBoundary && !UseLeftBoundary && !UseRightBoundary)
            {
                NumericBoundaries.UseNumericBoundaries = false;
                return;
            }

            // Avoid unnecessary transitions
            var skip = true;

            if ((UseTopBoundary && NumericBoundaries.TopBoundary != TopBoundary))
            {
                skip = false;
            }
            if ((UseBottomBoundary && NumericBoundaries.BottomBoundary != BottomBoundary))
            {
                skip = false;
            }
            if ((UseLeftBoundary && NumericBoundaries.LeftBoundary != LeftBoundary))
            {
                skip = false;
            }
            if ((UseRightBoundary && NumericBoundaries.RightBoundary != RightBoundary))
            {
                skip = false;
            }
            if (skip)
            {
                return;
            }

            NumericBoundaries.UseNumericBoundaries = true;

            GetTargetBoundaries();

            _boundsAnim.UseTopBoundary    = UseTopBoundary;
            _boundsAnim.TopBoundary       = _targetTopBoundary;
            _boundsAnim.UseBottomBoundary = UseBottomBoundary;
            _boundsAnim.BottomBoundary    = _targetBottomBoundary;
            _boundsAnim.UseLeftBoundary   = UseLeftBoundary;
            _boundsAnim.LeftBoundary      = _targetLeftBoundary;
            _boundsAnim.UseRightBoundary  = UseRightBoundary;
            _boundsAnim.RightBoundary     = _targetRightBoundary;

            _boundsAnim.TransitionDuration = TransitionDuration;
            _boundsAnim.TransitionEaseType = TransitionEaseType;

            // Zoom
            if (ChangeZoom)
            {
                ProCamera2D.UpdateScreenSize(_initialCamSize / TargetZoom, ZoomSmoothness, TransitionEaseType);
            }

            // Start bounds animation
            _boundsAnim.Transition();

            // Move camera with the position overrider
            if (_boundsAnim.AnimsCount > 1)
            {
                if (NumericBoundaries.MoveCameraToTargetRoutine != null)
                {
                    NumericBoundaries.StopCoroutine(NumericBoundaries.MoveCameraToTargetRoutine);
                }

                NumericBoundaries.MoveCameraToTargetRoutine = NumericBoundaries.StartCoroutine(MoveCameraToTarget());
            }
        }
        IEnumerator Transition()
        {
            if (!UseTopBoundary && !UseBottomBoundary && !UseLeftBoundary && !UseRightBoundary)
            {
                NumericBoundaries.UseTopBoundary    = false;
                NumericBoundaries.UseBottomBoundary = false;
                NumericBoundaries.UseLeftBoundary   = false;
                NumericBoundaries.UseRightBoundary  = false;
                yield break;
            }

            var         position       = transform.position;
            var         topBoundary    = AreBoundariesRelative ? position.y + TopBoundary : TopBoundary;
            var         bottomBoundary = AreBoundariesRelative ? position.y + BottomBoundary : BottomBoundary;
            var         leftBoundary   = AreBoundariesRelative ? position.x + LeftBoundary : LeftBoundary;
            var         rightBoundary  = AreBoundariesRelative ? position.x + RightBoundary : RightBoundary;
            const float epsilon        = 0.01f;

            // Avoid unnecessary transitions
            var skip = true;

            if (UseTopBoundary && (Mathf.Abs(NumericBoundaries.TopBoundary - topBoundary) > epsilon || !NumericBoundaries.UseTopBoundary))
            {
                skip = false;
            }
            if (skip && UseBottomBoundary && (Mathf.Abs(NumericBoundaries.BottomBoundary - bottomBoundary) > epsilon || !NumericBoundaries.UseBottomBoundary))
            {
                skip = false;
            }
            if (skip && UseLeftBoundary && (Mathf.Abs(NumericBoundaries.LeftBoundary - leftBoundary) > epsilon || !NumericBoundaries.UseLeftBoundary))
            {
                skip = false;
            }
            if (skip && UseRightBoundary && (Mathf.Abs(NumericBoundaries.RightBoundary - rightBoundary) > epsilon || !NumericBoundaries.UseRightBoundary))
            {
                skip = false;
            }
            if (skip)
            {
                yield break;
            }

            GetTargetBoundaries();

            _boundsAnim.UseTopBoundary    = UseTopBoundary;
            _boundsAnim.TopBoundary       = _targetTopBoundary;
            _boundsAnim.UseBottomBoundary = UseBottomBoundary;
            _boundsAnim.BottomBoundary    = _targetBottomBoundary;
            _boundsAnim.UseLeftBoundary   = UseLeftBoundary;
            _boundsAnim.LeftBoundary      = _targetLeftBoundary;
            _boundsAnim.UseRightBoundary  = UseRightBoundary;
            _boundsAnim.RightBoundary     = _targetRightBoundary;

            _boundsAnim.TransitionDuration = TransitionDuration;
            _boundsAnim.TransitionEaseType = TransitionEaseType;

            // Zoom
            if (ChangeZoom && _initialCamSize / TargetZoom != ProCamera2D.ScreenSizeInWorldCoordinates.y * .5f)
            {
                ProCamera2D.UpdateScreenSize(_initialCamSize / TargetZoom, ZoomSmoothness, TransitionEaseType);
            }


            // Move camera "manually"
            if (_boundsAnim.GetAnimsCount() > 1)
            {
                if (NumericBoundaries.MoveCameraToTargetRoutine != null)
                {
                    NumericBoundaries.StopCoroutine(NumericBoundaries.MoveCameraToTargetRoutine);
                }

                NumericBoundaries.MoveCameraToTargetRoutine = NumericBoundaries.StartCoroutine(MoveCameraToTarget());
            }

            // Start bounds animation
            yield return(new WaitForEndOfFrame());

            _boundsAnim.Transition();


            //if (CameraController.instance.setBoudariesLeft)
            //{
            //    CameraController.instance.setBoudariesLeft = false;
            //        GameController.instance.currentMap.BeginAutoSpawn(GameController.instance.currentMap.autoSpawnEnemys[CameraController.instance.currentCamBoidaries].autoSpawnEnemy);
            //}
        }