public virtual void MakeSequencesCircular() { for (int i = 0; i < viewSequences.Length; i++) { CameraViewTarget lastView = viewSequences[i].GetLast(); if (lastView.nextView == null) { lastView.nextView = viewSequences[i]; } } }
/// <summary> /// Can this view reach itself? /// </summary> /// <returns></returns> public bool IsCircular() { for (CameraViewTarget next = nextView; next != null; next = next.nextView) { if (next == this) { return(true); } } return(false); }
public int GetNumRemaining() { int totalRemaining = 0; for (CameraViewTarget next = nextView; next != null; next = next.nextView) { if (next == this) { return(totalRemaining); } totalRemaining++; } return(totalRemaining); }
/// <summary> /// Returns the last CameraView in the sequence. /// If the sequence is circular, returns the CameraView that connects to this one. /// </summary> /// <returns> /// The last CameraView in the sequence. /// </returns> public CameraViewTarget GetLast() { CameraViewTarget last = nextView; for (CameraViewTarget next = nextView; next != null; next = next.nextView) { if (next == this) { return(last); } last = next; } return(last); }
/// <summary> /// Lerps between camera's current position and transform position. /// </summary> /// <returns></returns> IEnumerator LerpView(Camera targetCamera, CameraViewTarget rootViewTarget) { for (CameraViewTarget viewTarget = rootViewTarget; viewTarget != null; viewTarget = viewTarget.nextView) { for (float timeElapsed = 0f; timeElapsed < viewTarget.duration; timeElapsed += Time.deltaTime) { targetCamera.transform.position = Vector3.Lerp(targetCamera.transform.position, viewTarget.viewPosition, Time.deltaTime); targetCamera.transform.rotation = Quaternion.Lerp(targetCamera.transform.rotation, Quaternion.Euler(viewTarget.viewRotation), Time.deltaTime); yield return(null); } if (captureEnabled) { CaptureView(); } } LerpSequenceComplete(targetCamera, rootViewTarget); }
public virtual void AddCameraView(int viewCameraId, CameraViewTarget viewTarget) { if (viewSequences[viewCameraId] == null) { viewSequences[viewCameraId] = viewTarget; } else { CameraViewTarget lastView = viewSequences[viewCameraId].GetLast(); if (lastView == null) { viewSequences[viewCameraId].nextView = viewTarget; } else { lastView.nextView = viewTarget; } } }
/// <summary> /// Called when duration has been reached. /// If nextView is valid, BeginView is called again. /// </summary> protected virtual void LerpSequenceComplete(Camera targetCamera, CameraViewTarget viewTarget) { StopCoroutine(viewLerpCoroutines[targetCamera]); viewLerpCoroutines.Remove(targetCamera); OnViewSequenceComplete.Invoke(targetCamera, viewTarget); }
/// <summary> /// Starts the LerpView coroutine /// </summary> /// <param name="targetCamera"></param> public void BeginView(Camera targetCamera, CameraViewTarget viewTarget) { viewLerpCoroutines.Add(targetCamera, LerpView(targetCamera, viewTarget)); StartCoroutine(viewLerpCoroutines[targetCamera]); }