public void Transition()
        {
            if (!NumericBoundaries.HasFiredTransitionStarted && OnTransitionStarted != null)
            {
                NumericBoundaries.HasFiredTransitionStarted = true;
                OnTransitionStarted();
            }

            NumericBoundaries.HasFiredTransitionFinished = false;

            NumericBoundaries.UseNumericBoundaries = true;

            // Animate boundaries
            if (UseLeftBoundary)
            {
                NumericBoundaries.UseLeftBoundary = true;

                if (NumericBoundaries.LeftBoundaryAnimRoutine != null)
                {
                    NumericBoundaries.StopCoroutine(NumericBoundaries.LeftBoundaryAnimRoutine);
                }

                NumericBoundaries.LeftBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(LeftTransitionRoutine(TransitionDuration));
            }
            else if (!UseLeftBoundary && NumericBoundaries.UseLeftBoundary && UseRightBoundary && RightBoundary < NumericBoundaries.TargetLeftBoundary)
            {
                NumericBoundaries.UseLeftBoundary = true;
                UseLeftBoundary = true;

                LeftBoundary = RightBoundary - ProCamera2D.ScreenSizeInWorldCoordinates.x * 100f;

                if (NumericBoundaries.LeftBoundaryAnimRoutine != null)
                {
                    NumericBoundaries.StopCoroutine(NumericBoundaries.LeftBoundaryAnimRoutine);
                }

                NumericBoundaries.LeftBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(LeftTransitionRoutine(TransitionDuration, true));
            }
            else if (!UseLeftBoundary)
            {
                NumericBoundaries.UseLeftBoundary = false;
            }

            if (UseRightBoundary)
            {
                NumericBoundaries.UseRightBoundary = true;

                if (NumericBoundaries.RightBoundaryAnimRoutine != null)
                {
                    NumericBoundaries.StopCoroutine(NumericBoundaries.RightBoundaryAnimRoutine);
                }

                NumericBoundaries.RightBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(RightTransitionRoutine(TransitionDuration));
            }
            else if (!UseRightBoundary && NumericBoundaries.UseRightBoundary && UseLeftBoundary && LeftBoundary > NumericBoundaries.TargetRightBoundary)
            {
                NumericBoundaries.UseRightBoundary = true;
                UseRightBoundary = true;

                RightBoundary = LeftBoundary + ProCamera2D.ScreenSizeInWorldCoordinates.x * 100f;

                if (NumericBoundaries.RightBoundaryAnimRoutine != null)
                {
                    NumericBoundaries.StopCoroutine(NumericBoundaries.RightBoundaryAnimRoutine);
                }

                NumericBoundaries.RightBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(RightTransitionRoutine(TransitionDuration, true));
            }
            else if (!UseRightBoundary)
            {
                NumericBoundaries.UseRightBoundary = false;
            }

            if (UseTopBoundary)
            {
                NumericBoundaries.UseTopBoundary = true;

                if (NumericBoundaries.TopBoundaryAnimRoutine != null)
                {
                    NumericBoundaries.StopCoroutine(NumericBoundaries.TopBoundaryAnimRoutine);
                }

                NumericBoundaries.TopBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(TopTransitionRoutine(TransitionDuration));
            }
            else if (!UseTopBoundary && NumericBoundaries.UseTopBoundary && UseBottomBoundary && BottomBoundary > NumericBoundaries.TargetTopBoundary)
            {
                NumericBoundaries.UseTopBoundary = true;
                UseTopBoundary = true;

                TopBoundary = BottomBoundary + ProCamera2D.ScreenSizeInWorldCoordinates.y * 100f;

                if (NumericBoundaries.TopBoundaryAnimRoutine != null)
                {
                    NumericBoundaries.StopCoroutine(NumericBoundaries.TopBoundaryAnimRoutine);
                }

                NumericBoundaries.TopBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(TopTransitionRoutine(TransitionDuration, true));
            }
            else if (!UseTopBoundary)
            {
                NumericBoundaries.UseTopBoundary = false;
            }

            if (UseBottomBoundary)
            {
                NumericBoundaries.UseBottomBoundary = true;

                if (NumericBoundaries.BottomBoundaryAnimRoutine != null)
                {
                    NumericBoundaries.StopCoroutine(NumericBoundaries.BottomBoundaryAnimRoutine);
                }

                NumericBoundaries.BottomBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(BottomTransitionRoutine(TransitionDuration));
            }
            else if (!UseBottomBoundary && NumericBoundaries.UseBottomBoundary && UseTopBoundary && TopBoundary < NumericBoundaries.TargetBottomBoundary)
            {
                NumericBoundaries.UseBottomBoundary = true;
                UseBottomBoundary = true;

                BottomBoundary = TopBoundary - ProCamera2D.ScreenSizeInWorldCoordinates.y * 100f;

                if (NumericBoundaries.BottomBoundaryAnimRoutine != null)
                {
                    NumericBoundaries.StopCoroutine(NumericBoundaries.BottomBoundaryAnimRoutine);
                }

                NumericBoundaries.BottomBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(BottomTransitionRoutine(TransitionDuration, true));
            }
            else if (!UseBottomBoundary)
            {
                NumericBoundaries.UseBottomBoundary = false;
            }

            //  Debug.Log("chuyenr????????");
        }
Exemple #2
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.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();
        }
        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);
            //}
        }