/// <summary>
        /// Create a blend from one ICinemachineCamera to another,
        /// or to/from a point, if we can't do anything else
        /// </summary>
        private CinemachineBlend CreateBlend(
            ICinemachineCamera camA, ICinemachineCamera camB,
            AnimationCurve blendCurve, float duration,
            CinemachineBlend activeBlend)
        {
            //UnityEngine.Profiling.Profiler.BeginSample("CinemachineTrackedDolly.MutateCameraState");
            if (blendCurve == null || duration <= 0 || (camA == null && camB == null))
            {
                //UnityEngine.Profiling.Profiler.EndSample();
                return(null);
            }
            if (camA == null || activeBlend != null)
            {
                // Blend from the current camera position
                CameraState state = CameraState.Default;
                if (activeBlend != null)
                {
                    state = activeBlend.State;
                }
                else
                {
                    state.RawPosition    = transform.position;
                    state.RawOrientation = transform.rotation;
                    state.Lens           = LensSettings.FromCamera(OutputCamera);
                }
                camA = new StaticPointVirtualCamera(state, activeBlend == null ? "(none)" : "Mid-blend");
            }
            CinemachineBlend blend = new CinemachineBlend(camA, camB, blendCurve, duration, 0);

            //UnityEngine.Profiling.Profiler.EndSample();
            return(blend);
        }
        /// <summary>Internal use only.  Do not call this method</summary>
        public override void InternalUpdateCameraState(Vector3 worldUp, float deltaTime)
        {
            // Get the state from the camera
            if (m_Camera == null)
            {
                m_Camera = GetComponent <Camera>();
            }

            m_State                = CameraState.Default;
            m_State.RawPosition    = transform.position;
            m_State.RawOrientation = transform.rotation;
            m_State.ReferenceUp    = m_State.RawOrientation * Vector3.up;
            if (m_Camera != null)
            {
                m_State.Lens = LensSettings.FromCamera(m_Camera);
            }

            if (m_LookAt != null)
            {
                m_State.ReferenceLookAt = m_LookAt.transform.position;
                Vector3 dir = m_State.ReferenceLookAt - State.RawPosition;
                if (!dir.AlmostZero())
                {
                    m_State.ReferenceLookAt = m_State.RawPosition + Vector3.Project(
                        dir, State.RawOrientation * Vector3.forward);
                }
            }
            SetPositionBlendMethod(ref m_State, m_PositionBlending);
            InvokePostPipelineStageCallback(this, CinemachineCore.Stage.Finalize, ref m_State, deltaTime);
        }
        /// <summary>Construct a CameraState object from the Unity Camera</summary>
        public override void UpdateCameraState(Vector3 worldUp, float deltaTime)
        {
            // Get the state from the camera
            if (m_Camera == null)
            {
                m_Camera = GetComponent <Camera>();
            }

            m_State                = CameraState.Default;
            m_State.RawPosition    = transform.position;
            m_State.RawOrientation = transform.rotation;
            m_State.ReferenceUp    = m_State.RawOrientation * Vector3.up;
            if (m_Camera != null)
            {
                m_State.Lens = LensSettings.FromCamera(m_Camera);
            }

            if (m_LookAt != null)
            {
                m_State.ReferenceLookAt = m_LookAt.transform.position;
                Vector3 dir = m_State.ReferenceLookAt - State.RawPosition;
                if (!dir.AlmostZero())
                {
                    m_State.ReferenceLookAt = m_State.RawPosition + Vector3.Project(
                        dir, State.RawOrientation * Vector3.forward);
                }
            }
        }
Example #4
0
        private void ProcessActiveCamera(float deltaTime)
        {
            var activeCamera = ActiveVirtualCamera;

            if (activeCamera == null)
            {
                // No active virtal camera.  We create a state representing its position
                // and call the callback, but we don't actively set the transform or lens
                var state = CameraState.Default;
                state.RawPosition    = transform.position;
                state.RawOrientation = transform.rotation;
                state.Lens           = LensSettings.FromCamera(m_OutputCamera);
                state.BlendHint     |= CameraState.BlendHintValue.NoTransform | CameraState.BlendHintValue.NoLens;
                PushStateToUnityCamera(SoloCamera != null ? SoloCamera.State : state);
            }
            else
            {
                // Has the current camera changed this frame?
                if (mActiveCameraPreviousFrameGameObject == null)
                {
                    mActiveCameraPreviousFrame = null; // object was deleted
                }
                if (activeCamera != mActiveCameraPreviousFrame)
                {
                    // Notify incoming camera of transition
                    activeCamera.OnTransitionFromCamera(
                        mActiveCameraPreviousFrame, DefaultWorldUp, deltaTime);
                    if (m_CameraActivatedEvent != null)
                    {
                        m_CameraActivatedEvent.Invoke(activeCamera, mActiveCameraPreviousFrame);
                    }

                    // If we're cutting without a blend, send an event
                    if (!IsBlending || (mActiveCameraPreviousFrame != null &&
                                        !ActiveBlend.Uses(mActiveCameraPreviousFrame)))
                    {
                        if (m_CameraCutEvent != null)
                        {
                            m_CameraCutEvent.Invoke(this);
                        }
                        if (CinemachineCore.CameraCutEvent != null)
                        {
                            CinemachineCore.CameraCutEvent.Invoke(this);
                        }
                    }
                    // Re-update in case it's inactive
                    activeCamera.UpdateCameraState(DefaultWorldUp, deltaTime);
                }
                // Apply the vcam state to the Unity camera
                PushStateToUnityCamera(
                    SoloCamera != null ? SoloCamera.State : mCurrentLiveCameras.State);
            }
            mActiveCameraPreviousFrame = activeCamera;
            mActiveCameraPreviousFrameGameObject
                = activeCamera == null ? null : activeCamera.VirtualCameraGameObject;
        }
 private CinemachineBlend CreateBlend(ICinemachineCamera camA, ICinemachineCamera camB, AnimationCurve blendCurve, float duration, CinemachineBlend activeBlend)
 {
     if (blendCurve == null || duration <= 0f || (camA == null && camB == null))
     {
         return(null);
     }
     if (camA == null || activeBlend != null)
     {
         CameraState state = CameraState.Default;
         if (activeBlend != null)
         {
             state = activeBlend.State;
         }
         else
         {
             state.RawPosition    = base.transform.position;
             state.RawOrientation = base.transform.rotation;
             state.Lens           = LensSettings.FromCamera(this.OutputCamera);
         }
         camA = new StaticPointVirtualCamera(state, (activeBlend == null) ? "(none)" : "Mid-blend");
     }
     return(new CinemachineBlend(camA, camB, blendCurve, duration, 0f));
 }
Example #6
0
 /// <summary>
 /// Create a blend from one ICinemachineCamera to another,
 /// or to/from a point, if we can't do anything else
 /// </summary>
 private CinemachineBlend CreateBlend(
     ICinemachineCamera camA, ICinemachineCamera camB,
     CinemachineBlendDefinition blendDef,
     CinemachineBlend activeBlend, float deltaTime)
 {
     if (blendDef.BlendCurve == null || blendDef.m_Time <= 0 || (camA == null && camB == null))
     {
         return(null);
     }
     if (activeBlend != null)
     {
         camA = new BlendSourceVirtualCamera(activeBlend, deltaTime);
     }
     else if (camA == null)
     {
         // Blend from the current camera position
         CameraState state = CameraState.Default;
         state.RawPosition    = transform.position;
         state.RawOrientation = transform.rotation;
         state.Lens           = LensSettings.FromCamera(OutputCamera);
         camA = new StaticPointVirtualCamera(state, "(none)");
     }
     return(new CinemachineBlend(camA, camB, blendDef.BlendCurve, blendDef.m_Time, 0));
 }
 public override void UpdateCameraState(Vector3 worldUp, float deltaTime)
 {
     if (this.m_Camera == null)
     {
         this.m_Camera = base.GetComponent <Camera>();
     }
     this.m_State                = CameraState.Default;
     this.m_State.RawPosition    = base.transform.position;
     this.m_State.RawOrientation = base.transform.rotation;
     this.m_State.ReferenceUp    = this.m_State.RawOrientation * Vector3.up;
     if (this.m_Camera != null)
     {
         this.m_State.Lens = LensSettings.FromCamera(this.m_Camera);
     }
     if (this.m_LookAt != null)
     {
         this.m_State.ReferenceLookAt = this.m_LookAt.transform.position;
         Vector3 vector = this.m_State.ReferenceLookAt - this.State.RawPosition;
         if (!vector.AlmostZero())
         {
             this.m_State.ReferenceLookAt = this.m_State.RawPosition + Vector3.Project(vector, this.State.RawOrientation * Vector3.forward);
         }
     }
 }