2022-08-31【unity】Cinemachine源码分析
- CinemachineBrain.ManualUpdate
m_LastFrameUpdated:总Frame数量
deltaTime
UpdateFrame0(deltaTime)
1012041001
outGoingCamera:frame.blend.camB:FakeJnCamera
LookupBlend(outGoingCamera, activeCamera)
blend = GetBlend(from,to)
BlendAB如果突然激活一个VirtualCameraGameObject,会触发
activeCamera != outGoingCamera
m_CustomBlends.GetBlendForVirtualCameras(from, to, blend)
找到anyToMe_Blend 和 meToAny_Blend
ComputeCurrentBlend
BrainFrame.workingBlend.CamA:null
BrainFrame.workingBlend.CamB:FakeJnCamera
BlendCurve:null
Duration:0
TimeInBlend:0
=》outputBlend
LookupBlend
UpdateVirtualCameras
Camera camera = OutputCamera
CinemachineCore.Instance.UpdateAllActiveVirtualCameras
- UpdateVirtualCamera
LateUpdate:int frameDelta = Time.frameCount - status.lastUpdateFrame
deltaTime *= frameDelta //try to catch up if multiple frames 如果更新了多帧,追赶上
(CinemachineVirtualCamera)vcam.InternalUpdateCameraState(deltaTime)
- UpdateTargetCache
Follow:FakeJnCamera
LookAt:Null- m_State = CalculateNewState(deltaTime)
- PullStateFromVirtualCamera
state.RawPosition = TargetPositionCache.GetTargetPosition(transform)
state.RawRotation = TargetPositionCache.GetTargetRotation(transform)CacheMode == Mode.Disabled,直接返回transform坐标旋转
lens.SnapshotCameraReadOnlyProperties(brain.OutputCamera)// 记录相机参数- UpdateComponentPipeline
- ApplyPositionBlendMethod
mCurrentLiveCameras.UpdateCameraState
ProcessActiveCamera
1.判断SoloCamera是否存在
2.判断当前是否有激活VirtualCamera,没有的话会根据当前CinemachineBrain所在位置创建一个虚假的CameraState进行过渡。
RawPosition; RawOrientation; Lens; BlendHint
3.两个相机过渡
PushStateToUnityCamera
CurrentCameraState = state
CinemachineCore.CameraUpdatedEvent.Invoke(this);=>
CinemachineStoryboard.StaticBlendingHandler(brain)
CinemachineVolumeSettings.ApplyPostFX(brain)