Beispiel #1
0
        void LimitToNumericBoundaries(
            ref float horizontalPos,
            ref float verticalPos,
            float halfCameraWidth,
            float halfCameraHeight,
            NumericBoundariesSettings numericBoundaries)
        {
            if (numericBoundaries.UseLeftBoundary && horizontalPos - halfCameraWidth < numericBoundaries.LeftBoundary)
            {
                horizontalPos = numericBoundaries.LeftBoundary + halfCameraWidth;
            }
            else if (numericBoundaries.UseRightBoundary && horizontalPos + halfCameraWidth > numericBoundaries.RightBoundary)
            {
                horizontalPos = numericBoundaries.RightBoundary - halfCameraWidth;
            }

            if (numericBoundaries.UseBottomBoundary && verticalPos - halfCameraHeight < numericBoundaries.BottomBoundary)
            {
                verticalPos = numericBoundaries.BottomBoundary + halfCameraHeight;
            }
            else if (numericBoundaries.UseTopBoundary && verticalPos + halfCameraHeight > numericBoundaries.TopBoundary)
            {
                verticalPos = numericBoundaries.TopBoundary - halfCameraHeight;
            }
        }
        IEnumerator TransitionRoutine(NumericBoundariesSettings numericBoundariesSettings, float targetSize, float transitionDuration = 1f, EaseType transitionEaseType = EaseType.EaseOut)
        {
            _transitioning = true;

            // Disable the current numeric boundaries
            _numericBoundaries.UseNumericBoundaries = false;

            // Size
            var initialSize = ProCamera2D.ScreenSizeInWorldCoordinates.y / 2f;

            //Position
            var initialCamPosH = Vector3H(ProCamera2D.LocalPosition);
            var initialCamPosV = Vector3V(ProCamera2D.LocalPosition);

            // Transition
            var t = 0f;

            while (t <= 1.0f)
            {
                t += ProCamera2D.DeltaTime / transitionDuration;

                // Size
                _newSize = Utils.EaseFromTo(initialSize, targetSize, t, transitionEaseType);

                // Position
                var targetPosH = ProCamera2D.CameraTargetPositionSmoothed.x;
                var targetPosV = ProCamera2D.CameraTargetPositionSmoothed.y;

                LimitToNumericBoundaries(
                    ref targetPosH,
                    ref targetPosV,
                    targetSize * ProCamera2D.GameCamera.aspect,
                    targetSize,
                    numericBoundariesSettings);

                var newPosH = Utils.EaseFromTo(initialCamPosH, targetPosH, t, transitionEaseType);
                var newPosV = Utils.EaseFromTo(initialCamPosV, targetPosV, t, transitionEaseType);
                _newPos = VectorHVD(newPosH, newPosV, 0);

                yield return(ProCamera2D.GetYield());
            }

            _transitioning = false;

            _numericBoundaries.Settings = numericBoundariesSettings;

            _transitionRoutine = null;

            if (OnFinishedTransition != null)
            {
                OnFinishedTransition.Invoke(_currentRoomIndex, _previousRoomIndex);
            }

            _previousRoomIndex = _currentRoomIndex;
        }
Beispiel #3
0
        override protected void Awake()
        {
            base.Awake();

            _numericBoundaries = ProCamera2D.GetComponent <ProCamera2DNumericBoundaries>();
            _defaultNumericBoundariesSettings = _numericBoundaries.Settings;

            OriginalSize = ProCamera2D.ScreenSizeInWorldCoordinates.y / 2;

            ProCamera2D.AddPositionOverrider(this);
            ProCamera2D.AddSizeOverrider(this);
        }
Beispiel #4
0
        void TransitionToRoom(Room room, bool useTransition = true)
        {
            // Stop any previous transition
            if (_transitionRoutine != null)
            {
                StopCoroutine(_transitionRoutine);
            }

            // Numeric boundaries
            var numericBoundariesSettings = new NumericBoundariesSettings()
            {
                UseNumericBoundaries = true,
                UseTopBoundary       = true,
                TopBoundary          = (room.Dimensions.y + (UseRelativePosition ? _transform.position.y : 0)) + room.Dimensions.height / 2,
                UseBottomBoundary    = true,
                BottomBoundary       = (room.Dimensions.y + (UseRelativePosition ? _transform.position.y : 0)) - room.Dimensions.height / 2,
                UseLeftBoundary      = true,
                LeftBoundary         = (room.Dimensions.x + (UseRelativePosition ? _transform.position.x : 0)) - room.Dimensions.width / 2,
                UseRightBoundary     = true,
                RightBoundary        = (room.Dimensions.x + (UseRelativePosition ? _transform.position.x : 0)) + room.Dimensions.width / 2
            };

            // Size
            var targetSize        = ProCamera2D.ScreenSizeInWorldCoordinates.y / 2f;
            var cameraSizeForRoom = GetCameraSizeForRoom(room.Dimensions);

            if (room.ScaleCameraToFit)
            {
                targetSize = cameraSizeForRoom;
            }
            else if (room.Zoom && OriginalSize * room.ZoomScale <= cameraSizeForRoom)
            {
                targetSize = OriginalSize * room.ZoomScale;
            }
            else if (cameraSizeForRoom < targetSize)
            {
                targetSize = cameraSizeForRoom;
            }

            // Move camera "manually"
            _transitionRoutine = StartCoroutine(TransitionRoutine(numericBoundariesSettings, targetSize, useTransition ? room.TransitionDuration : 0f, room.TransitionEaseType));
        }
Beispiel #5
0
 /// <summary>
 /// Sets the default numeric boundaries settings (i.e. The boundaries to use when not inside any room).
 /// </summary>
 /// <param name="settings">The numeric boundaries settings.
 /// You can grab them from the NumericBoundaries extension, or manually create them</param>
 public void SetDefaultNumericBoundariesSettings(NumericBoundariesSettings settings)
 {
     _defaultNumericBoundariesSettings = settings;
 }