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)); }
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; }
public void RemoveVirtualCamera(VirtualCamera virtualCamera) { if (!_virtualCameras.Contains(virtualCamera)) { return; } _virtualCameras.Remove(virtualCamera); SetActiveVirtualCamera(GetActiveVirtualCamera()); }
public void AddVirtualCamera(VirtualCamera virtualCamera) { if (_virtualCameras.Contains(virtualCamera)) { return; } _virtualCameras.Add(virtualCamera); ReorderVirtualCameras(); SetActiveVirtualCamera(GetActiveVirtualCamera()); }
public void SetActiveVirtualCamera(VirtualCamera newVirtualCamera) { if (!newVirtualCamera) { return; } if (_activeVirtualCamera && newVirtualCamera != _activeVirtualCamera) { OnActiveVirtualCameraChange(newVirtualCamera); } _activeVirtualCamera = newVirtualCamera; }
void UpdateCameraOrthographicSize(VirtualCamera virtualCamera) { SetCameraOrthographicSize(virtualCamera.orthographicSize); }
void UpdateCameraPosition(VirtualCamera virtualCamera) { SetCameraPosition(virtualCamera.GetTargetPosition()); }