private IEnumerator AfterPhysics() { while (true) { // FixedUpdate can be called multiple times per frame yield return(mWaitForFixedUpdate); if (m_UpdateMethod == UpdateMethod.FixedUpdate || m_UpdateMethod == UpdateMethod.SmartUpdate) { CinemachineCore.UpdateFilter filter = CinemachineCore.UpdateFilter.Fixed; if (m_UpdateMethod == UpdateMethod.SmartUpdate) { // Track the targets UpdateTracker.OnUpdate(UpdateTracker.UpdateClock.Fixed); filter = CinemachineCore.UpdateFilter.SmartFixed; } UpdateVirtualCameras(filter, GetEffectiveDeltaTime(true)); } // Choose the active vcam and apply it to the Unity camera if (m_BlendUpdateMethod == BrainUpdateMethod.FixedUpdate) { UpdateFrame0(Time.fixedDeltaTime); ProcessActiveCamera(Time.fixedDeltaTime); } } }
/// <summary> /// Update a single Cinemachine Virtual Camera if and only if it /// hasn't already been updated this frame. Always update vcams via this method. /// Calling this more than once per frame for the same camera will have no effect. /// </summary> internal void UpdateVirtualCamera( CinemachineVirtualCameraBase vcam, Vector3 worldUp, float deltaTime) { if (vcam == null) { return; } bool isSmartUpdate = (CurrentUpdateFilter & UpdateFilter.Smart) == UpdateFilter.Smart; UpdateTracker.UpdateClock updateClock = (UpdateTracker.UpdateClock)(CurrentUpdateFilter & ~UpdateFilter.Smart); // If we're in smart update mode and the target moved, then we must examine // how the target has been moving recently in order to figure out whether to // update now if (isSmartUpdate) { Transform updateTarget = GetUpdateTarget(vcam); if (updateTarget == null) { return; // vcam deleted } if (UpdateTracker.GetPreferredUpdate(updateTarget) != updateClock) { return; // wrong clock } } // Have we already been updated this frame? if (mUpdateStatus == null) { mUpdateStatus = new Dictionary <CinemachineVirtualCameraBase, UpdateStatus>(); } UpdateStatus status; if (!mUpdateStatus.TryGetValue(vcam, out status)) { status = new UpdateStatus(); mUpdateStatus.Add(vcam, status); } int frameDelta = (updateClock == UpdateTracker.UpdateClock.Late) ? Time.frameCount - status.lastUpdateFrame : FixedFrameCount - status.lastUpdateFixedFrame; if (deltaTime >= 0 && frameDelta == 0 && status.lastUpdateMode == updateClock) { return; // already updated } if (frameDelta != 1) { deltaTime = -1; // multiple frames - kill the damping } //Debug.Log((vcam.ParentCamera == null ? "" : vcam.ParentCamera.Name + ".") + vcam.Name + ": frame " + Time.frameCount + "/" + status.lastUpdateFixedFrame + ", " + CurrentUpdateFilter + ", deltaTime = " + deltaTime); vcam.InternalUpdateCameraState(worldUp, deltaTime); status.lastUpdateFrame = Time.frameCount; status.lastUpdateFixedFrame = FixedFrameCount; status.lastUpdateMode = updateClock; }
private void LateUpdate() { float deltaTime = GetEffectiveDeltaTime(false); UpdateFrame0(deltaTime); UpdateCurrentLiveCameras(); if (m_UpdateMethod == UpdateMethod.FixedUpdate) { // Special handling for fixed update: cameras that have been enabled // since the last physics frame must be updated now CinemachineCore.Instance.CurrentUpdateFilter = CinemachineCore.UpdateFilter.Fixed; if (SoloCamera != null) { SoloCamera.UpdateCameraState(DefaultWorldUp, deltaTime); } mCurrentLiveCameras.UpdateCameraState(DefaultWorldUp, deltaTime); } else { CinemachineCore.UpdateFilter filter = CinemachineCore.UpdateFilter.Late; if (m_UpdateMethod == UpdateMethod.SmartUpdate) { // Track the targets UpdateTracker.OnUpdate(UpdateTracker.UpdateClock.Late); filter = CinemachineCore.UpdateFilter.SmartLate; } UpdateVirtualCameras(filter, deltaTime); } // Choose the active vcam and apply it to the Unity camera ProcessActiveCamera(deltaTime); }
/// <summary> /// Call this method explicitly from an external script to update the virtual cameras /// and position the main camera, if the UpdateMode is set to ManualUpdate. /// For other update modes, this method is called automatically, and should not be /// called from elsewhere. /// </summary> public void ManualUpdate() { m_LastFrameUpdated = Time.frameCount; float deltaTime = GetEffectiveDeltaTime(false); if (!Application.isPlaying || m_BlendUpdateMethod != BrainUpdateMethod.FixedUpdate) { UpdateFrame0(deltaTime); } ComputeCurrentBlend(ref mCurrentLiveCameras, 0); if (m_UpdateMethod == UpdateMethod.FixedUpdate) { // Special handling for fixed update: cameras that have been enabled // since the last physics frame must be updated now if (m_BlendUpdateMethod != BrainUpdateMethod.FixedUpdate) { CinemachineCore.Instance.m_CurrentUpdateFilter = CinemachineCore.UpdateFilter.Fixed; if (SoloCamera == null) { mCurrentLiveCameras.UpdateCameraState( DefaultWorldUp, GetEffectiveDeltaTime(true)); } } } else { CinemachineCore.UpdateFilter filter = CinemachineCore.UpdateFilter.Late; if (m_UpdateMethod == UpdateMethod.SmartUpdate) { // Track the targets UpdateTracker.OnUpdate(UpdateTracker.UpdateClock.Late); filter = CinemachineCore.UpdateFilter.SmartLate; } UpdateVirtualCameras(filter, deltaTime); } // Choose the active vcam and apply it to the Unity camera if (!Application.isPlaying || m_BlendUpdateMethod != BrainUpdateMethod.FixedUpdate) { ProcessActiveCamera(deltaTime); } }
private void LateUpdate() { float deltaTime = GetEffectiveDeltaTime(false); if (m_UpdateMethod != UpdateMethod.FixedUpdate) { CinemachineCore.UpdateFilter filter = CinemachineCore.UpdateFilter.Late; if (m_UpdateMethod == UpdateMethod.SmartUpdate) { // Track the targets UpdateTracker.OnUpdate(UpdateTracker.UpdateClock.Late); filter = CinemachineCore.UpdateFilter.SmartLate; } UpdateVirtualCameras(filter, deltaTime); } // Choose the active vcam and apply it to the Unity camera ProcessActiveCamera(deltaTime); }
private IEnumerator AfterPhysics() { while (true) { // FixedUpdate can be called multiple times per frame yield return(mWaitForFixedUpdate); if (m_UpdateMethod != UpdateMethod.LateUpdate) { CinemachineCore.UpdateFilter filter = CinemachineCore.UpdateFilter.Fixed; if (m_UpdateMethod == UpdateMethod.SmartUpdate) { // Track the targets UpdateTracker.OnUpdate(UpdateTracker.UpdateClock.Fixed); filter = CinemachineCore.UpdateFilter.SmartFixed; } UpdateVirtualCameras(filter, GetEffectiveDeltaTime(true)); } } }