Example #1
0
        public void OnActiveVirtualCameraChange(VirtualCamera newCamera)
        {
            if (_transitionRoutine != null)
            {
                StopCoroutine(_transitionRoutine);
            }

            CameraTransition transition = newCamera.overrideTransition ? newCamera.transition : this.transition;

            if (transition.duration == 0)
            {
                onTransitionStart.Invoke();
                newCamera.onTransitionStart.Invoke();

                SetCameraPosition(newCamera.GetTargetPosition());
                SetCameraOrthographicSize(newCamera.orthographicSize);

                onTransitionEnd.Invoke();
                newCamera.onTransitionEnd.Invoke();

                return;
            }

            _transitionRoutine = StartCoroutine(TransitionRoutine(newCamera, transition));
        }
Example #2
0
        private IEnumerator TransitionRoutine(VirtualCamera virtualCamera, CameraTransition transition)
        {
            onTransitionStart.Invoke();
            virtualCamera.onTransitionStart.Invoke();

            Vector3 startPosition = _camera.transform.position;

            float startSize = _camera.orthographicSize;
            float endSize   = virtualCamera.orthographicSize;

            float t = 0;

            while (t < transition.duration)
            {
                t += transition.ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime;
                float p = t / transition.duration;
                float i = Easing.Interpolate(p, transition.easing);

                SetCameraPosition(Vector3.LerpUnclamped(startPosition, virtualCamera.GetTargetPosition(), i));
                SetCameraOrthographicSize(Mathf.LerpUnclamped(startSize, endSize, i));

                yield return(null);
            }

            onTransitionEnd.Invoke();
            virtualCamera.onTransitionEnd.Invoke();

            _transitionRoutine = null;
        }