public void startKeyframeAnimation(CameraAttribute?from, CameraAttribute to, float time, AnimationCurve curve = null) { if (from != null) { m_CamController.setAttribute(from.Value); } StartCoroutine(ieStartCameraNextKeyframe(to, time, curve)); }
public void startLoopAnimation(CameraAttribute unscale) { if (m_LoopAnimator != null) { StopCoroutine(m_LoopAnimator); } var coro = StartCoroutine(ieCameraLoopAnimator(unscale)); m_LoopAnimator = coro; }
public IEnumerator ieStartCameraNextKeyframe(CameraAttribute attr, float time, AnimationCurve curve = null) { AnimationCurve animaCurve = m_DefaultCurve; if (curve != null) { animaCurve = curve; } lock (intp_lock) { float currentTime = 0f; float progress = 0f; var currentAttr = m_CamController.getAttribute(); var currPosition = currentAttr.position; var currRotation = currentAttr.rotation; var currLength = currentAttr.zlength; var currFov = currentAttr.fov; while (currentTime < time) { yield return(new WaitForEndOfFrame()); float deltaTime = Time.deltaTime; currentTime += deltaTime; progress = currentTime / time; float intp = animaCurve.Evaluate(progress); var frame = CameraAttribute.Empty; if (attr.position is Vector3 pos) { frame.position = Vector3.Lerp(currPosition, pos, intp); } if (attr.rotation is Quaternion rot) { frame.rotation = Quaternion.Slerp(currRotation, rot, intp); } if (attr.zlength is float length) { frame.zlength = Mathf.Lerp(currLength, length, intp); } if (attr.fov is float fov) { frame.fov = Mathf.Lerp(currFov, fov, intp); } m_CamController.setAttribute(frame); } m_CamController.setAttribute(attr); yield return(null); } }
private IEnumerator ieCameraLoopAnimator(CameraAttribute unscale) { while (true) { yield return(new WaitForEndOfFrame()); var cameraAttr = m_CamController.getAttribute(); cameraAttr = combineAttribute(cameraAttr, unscale, Time.deltaTime); m_CamController.setAttribute(cameraAttr); } }
/* Setter */ public void setAttribute(CameraAttribute attr) { if (attr.position is Vector3 pos) { m_WorldPosition = pos; } if (attr.rotation is Quaternion rot) { m_WorldRotation = rot; } if (attr.zlength is float length) { m_CurrentZLength = length; } if (attr.fov is float fov) { m_CurrentFov = fov; } }
/* Tools */ private CameraAttributeNotNull combineAttribute(CameraAttributeNotNull attr, CameraAttribute delta, float intp) { if (delta.position.HasValue) { attr.position += delta.position.Value * intp; } if (delta.rotation.HasValue) { attr.rotation *= Quaternion.Slerp(Quaternion.identity, delta.rotation.Value, intp); } if (delta.zlength.HasValue) { attr.zlength += delta.zlength.Value * intp; } if (delta.fov.HasValue) { attr.fov += delta.fov.Value * intp; } return(attr); }