// .. COROUTINES IEnumerator UpdateAnimation(Camera camera_to_animate) { float elapsed = 0f; float total_time = KeyFrames.Sum(e => e.TimeBetweenFrames); Transform camera_transform = camera_to_animate.GetComponent <Transform>(); while (elapsed < total_time) { float elapsed_frame = 0; CameraAnimationKeyframe from, to; GetCameraKeyFramesAtTime(elapsed, out from, out to); TransformValue from_transform = new TransformValue(from.CameraPreview == null ? camera_transform : from.CameraPreview.GetComponent <Transform>()); TransformValue to_transform = new TransformValue(to.CameraPreview.GetComponent <Transform>()); float from_fov = from.CameraPreview == null ? camera_to_animate.fieldOfView : from.CameraPreview.fieldOfView; float to_fov = to.CameraPreview.fieldOfView; while (elapsed_frame < to.TimeBetweenFrames) { float normalized_time = elapsed_frame / to.TimeBetweenFrames; //Transform EasingFunctions.Ease(to.TransformEaseType, normalized_time, from_transform, to_transform, ref camera_transform); //Field of View camera_to_animate.fieldOfView = EasingFunctions.Ease(to.FieldOfViewEaseType, normalized_time, from_fov, to_fov); elapsed += Time.deltaTime; elapsed_frame += Time.deltaTime; yield return(null); } camera_transform.localPosition = to_transform.LocalPosition; camera_transform.localRotation = to_transform.LocalRotation; camera_transform.localScale = to_transform.LocalScale; camera_to_animate.fieldOfView = to_fov; } if (OnAnimationCompleted != null) { OnAnimationCompleted.Invoke(this); } }
// .. ACCESSORS public float GetTotalAnimationTime() { return(KeyFrames.Sum(e => e.TimeBetweenFrames)); }