美文网首页
2022-08-31【unity】Cinemachine源码分析

2022-08-31【unity】Cinemachine源码分析

作者: 持刀的要迟到了 | 来源:发表于2022-08-30 22:14 被阅读0次
    • 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)

    相关文章

      网友评论

          本文标题:2022-08-31【unity】Cinemachine源码分析

          本文链接:https://www.haomeiwen.com/subject/nckdnrtx.html