示例#1
0
        /// <summary>Internal use only.  Called by CinemachineCore at designated update time
        /// so the vcam can position itself and track its targets.  This implementation
        /// updates all the children, chooses the best one, and implements any required blending.</summary>
        /// <param name="worldUp">Default world Up, set by the CinemachineBrain</param>
        /// <param name="deltaTime">Delta time for time-based effects (ignore if less than 0)</param>
        public override void InternalUpdateCameraState(Vector3 worldUp, float deltaTime)
        {
            //UnityEngine.Profiling.Profiler.BeginSample("CinemachineClearShot.InternalUpdateCameraState");
            if (!PreviousStateIsValid)
            {
                deltaTime = -1;
            }

            // Choose the best camera
            UpdateListOfChildren();
            ICinemachineCamera previousCam = LiveChild;

            LiveChild = ChooseCurrentCamera(worldUp, deltaTime);

            // Are we transitioning cameras?
            if (previousCam != null && LiveChild != null && previousCam != LiveChild)
            {
                // Create a blend (will be null if a cut)
                mActiveBlend = CreateBlend(
                    previousCam, LiveChild,
                    LookupBlend(previousCam, LiveChild), mActiveBlend, deltaTime);

                // Notify incoming camera of transition
                LiveChild.OnTransitionFromCamera(previousCam, worldUp, deltaTime);

                // Generate Camera Activation event if live
                CinemachineCore.Instance.GenerateCameraActivationEvent(LiveChild);

                // If cutting, generate a camera cut event if live
                if (mActiveBlend == null)
                {
                    CinemachineCore.Instance.GenerateCameraCutEvent(LiveChild);
                }
            }

            // Advance the current blend (if any)
            if (mActiveBlend != null)
            {
                mActiveBlend.TimeInBlend += (deltaTime >= 0)
                    ? deltaTime : mActiveBlend.Duration;
                if (mActiveBlend.IsComplete)
                {
                    mActiveBlend = null;
                }
            }

            if (mActiveBlend != null)
            {
                mActiveBlend.UpdateCameraState(worldUp, deltaTime);
                m_State = mActiveBlend.State;
            }
            else if (LiveChild != null)
            {
                m_State = LiveChild.State;
            }

            InvokePostPipelineStageCallback(this, CinemachineCore.Stage.Finalize, ref m_State, deltaTime);
            PreviousStateIsValid = true;
            //UnityEngine.Profiling.Profiler.EndSample();
        }
示例#2
0
        /// <summary>Internal use only.  Do not call this method.
        /// Called by CinemachineCore at designated update time
        /// so the vcam can position itself and track its targets.  This implementation
        /// updates all the children, chooses the best one, and implements any required blending.</summary>
        /// <param name="worldUp">Default world Up, set by the CinemachineBrain</param>
        /// <param name="deltaTime">Delta time for time-based effects (ignore if less than or equal to 0)</param>
        public override void InternalUpdateCameraState(Vector3 worldUp, float deltaTime)
        {
            UpdateListOfChildren();
            CinemachineVirtualCameraBase best = ChooseCurrentCamera();

            if (best != null && !best.gameObject.activeInHierarchy)
            {
                best.gameObject.SetActive(true);
                best.UpdateCameraState(worldUp, deltaTime);
            }

            ICinemachineCamera previousCam = LiveChild;

            LiveChild = best;

            // Are we transitioning cameras?
            if (previousCam != LiveChild && LiveChild != null)
            {
                // Notify incoming camera of transition
                LiveChild.OnTransitionFromCamera(previousCam, worldUp, deltaTime);

                // Generate Camera Activation event in the brain if live
                CinemachineCore.Instance.GenerateCameraActivationEvent(LiveChild, previousCam);

                if (previousCam != null)
                {
                    // Create a blend (will be null if a cut)
                    mActiveBlend = CreateBlend(
                        previousCam, LiveChild,
                        LookupBlend(previousCam, LiveChild), mActiveBlend);

                    // If cutting, generate a camera cut event if live
                    if (mActiveBlend == null || !mActiveBlend.Uses(previousCam))
                    {
                        CinemachineCore.Instance.GenerateCameraCutEvent(LiveChild);
                    }
                }
            }

            // Advance the current blend (if any)
            if (mActiveBlend != null)
            {
                mActiveBlend.TimeInBlend += (deltaTime >= 0)
                    ? deltaTime : mActiveBlend.Duration;
                if (mActiveBlend.IsComplete)
                {
                    mActiveBlend = null;
                }
            }

            if (mActiveBlend != null)
            {
                mActiveBlend.UpdateCameraState(worldUp, deltaTime);
                m_State = mActiveBlend.State;
            }
            else if (LiveChild != null)
            {
                if (TransitioningFrom != null)
                {
                    LiveChild.OnTransitionFromCamera(TransitioningFrom, worldUp, deltaTime);
                }
                m_State = LiveChild.State;
            }
            TransitioningFrom = null;
            InvokePostPipelineStageCallback(this, CinemachineCore.Stage.Finalize, ref m_State, deltaTime);
            PreviousStateIsValid = true;
        }
示例#3
0
        /// <summary>Called by <see cref="CinemachineCore"/> at designated update time
        /// so the vcam can position itself and track its targets.  This implementation
        /// updates all the children, chooses the best one, and implements any required blending.</summary>
        /// <param name="worldUp">Default world Up, set by the <see cref="CinemachineBrain"/></param>
        /// <param name="deltaTime">Delta time for time-based effects (ignore if less than or equal to 0)</param>
        public override void UpdateCameraState(Vector3 worldUp, float deltaTime)
        {
            if (PreviousStateInvalid)
            {
                deltaTime = -1;
            }
            PreviousStateInvalid = false;

            // Choose the best camera
            UpdateListOfChildren();
            ICinemachineCamera previousCam = LiveChild;

            LiveChild = ChooseCurrentCamera(worldUp, deltaTime);

            // Are we transitioning cameras?
            if (previousCam != null && LiveChild != null && previousCam != LiveChild)
            {
                // Create a blend (will be null if a cut)
                mActiveBlend = CreateBlend(
                    previousCam, LiveChild,
                    LookupBlendCurve(previousCam, LiveChild),
                    mActiveBlend, deltaTime);

                // Notify incoming camera of transition
                LiveChild.OnTransitionFromCamera(previousCam);

                // Generate Camera Activation event if live
                CinemachineCore.Instance.GenerateCameraActivationEvent(LiveChild);

                // If cutting, generate a camera cut event if live
                if (mActiveBlend == null)
                {
                    CinemachineCore.Instance.GenerateCameraCutEvent(LiveChild);
                }
            }

            // Advance the current blend (if any)
            if (mActiveBlend != null)
            {
                mActiveBlend.TimeInBlend += (deltaTime > 0)
                    ? deltaTime : mActiveBlend.Duration;
                if (mActiveBlend.IsComplete)
                {
                    mActiveBlend = null;
                }
            }

            if (mActiveBlend != null)
            {
                mActiveBlend.UpdateCameraState(worldUp, deltaTime);
                m_State = mActiveBlend.State;
            }
            else if (LiveChild != null)
            {
                m_State = LiveChild.State;
            }
            else
            {
                m_State = CameraState.Default;
            }

            // Push the raw position back to the game object's transform, so it
            // moves along with the camera.  Leave the orientation alone, because it
            // screws up camera dragging when there is a LookAt behaviour.
            if (Follow != null)
            {
                transform.position = State.RawPosition;
            }
        }
示例#4
0
        /// <summary>Called by CinemachineCore at designated update time
        /// so the vcam can position itself and track its targets.  This implementation
        /// updates all the children, chooses the best one, and implements any required blending.</summary>
        /// <param name="worldUp">Default world Up, set by the CinemachineBrain</param>
        /// <param name="deltaTime">Delta time for time-based effects (ignore if less than or equal to 0)</param>
        public override void InternalUpdateCameraState(Vector3 worldUp, float deltaTime)
        {
            if (!PreviousStateIsValid)
            {
                deltaTime = -1;
            }

            UpdateListOfChildren();

            AdvanceCurrentInstruction();
            CinemachineVirtualCameraBase best = null;

            if (mCurrentInstruction >= 0 && mCurrentInstruction < m_Instructions.Length)
            {
                best = m_Instructions[mCurrentInstruction].m_VirtualCamera;
            }

            if (best != null)
            {
                if (!best.gameObject.activeInHierarchy)
                {
                    best.gameObject.SetActive(true);
                    best.UpdateCameraState(worldUp, deltaTime);
                }
                ICinemachineCamera previousCam = LiveChild;
                LiveChild = best;

                // Are we transitioning cameras?
                if (previousCam != null && LiveChild != null && previousCam != LiveChild && mCurrentInstruction > 0)
                {
                    // Create a blend (will be null if a cut)
                    mActiveBlend = CreateBlend(
                        previousCam, LiveChild,
                        m_Instructions[mCurrentInstruction].m_Blend,
                        mActiveBlend);

                    // Notify incoming camera of transition
                    LiveChild.OnTransitionFromCamera(previousCam, worldUp, deltaTime);

                    // Generate Camera Activation event if live
                    CinemachineCore.Instance.GenerateCameraActivationEvent(LiveChild);

                    // If cutting, generate a camera cut event if live
                    if (mActiveBlend == null)
                    {
                        CinemachineCore.Instance.GenerateCameraCutEvent(LiveChild);
                    }
                }
            }

            // Advance the current blend (if any)
            if (mActiveBlend != null)
            {
                mActiveBlend.TimeInBlend += (deltaTime >= 0) ? deltaTime : mActiveBlend.Duration;
                if (mActiveBlend.IsComplete)
                {
                    mActiveBlend = null;
                }
            }

            if (mActiveBlend != null)
            {
                mActiveBlend.UpdateCameraState(worldUp, deltaTime);
                m_State = mActiveBlend.State;
            }
            else if (LiveChild != null)
            {
                m_State = LiveChild.State;
            }

            InvokePostPipelineStageCallback(this, CinemachineCore.Stage.Finalize, ref m_State, deltaTime);
            PreviousStateIsValid = true;
        }
示例#5
0
        /// <summary>
        ///     Called by CinemachineCore at designated update time
        ///     so the vcam can position itself and track its targets.  This implementation
        ///     updates all the children, chooses the best one, and implements any required blending.
        /// </summary>
        /// <param name="worldUp">Default world Up, set by the CinemachineBrain</param>
        /// <param name="deltaTime">Delta time for time-based effects (ignore if less than or equal to 0)</param>
        public override void UpdateCameraState(Vector3 worldUp, float deltaTime)
        {
            //UnityEngine.Profiling.Profiler.BeginSample("CinemachineStateDrivenCamera.UpdateCameraState");
            if (!PreviousStateIsValid)
            {
                deltaTime = -1;
            }

            UpdateListOfChildren();
            var best = ChooseCurrentCamera(deltaTime);

            if (m_ChildCameras != null)
            {
                for (var i = 0; i < m_ChildCameras.Length; ++i)
                {
                    var vcam = m_ChildCameras[i];
                    if (vcam != null)
                    {
                        var enableChild = m_EnableAllChildCameras || vcam == best;
                        if (enableChild != vcam.VirtualCameraGameObject.activeInHierarchy)
                        {
                            vcam.gameObject.SetActive(enableChild);
                            if (enableChild)
                            {
                                CinemachineCore.Instance.UpdateVirtualCamera(vcam, worldUp, deltaTime);
                            }
                        }
                    }
                }
            }

            var previousCam = LiveChild;

            LiveChild = best;

            // Are we transitioning cameras?
            if (previousCam != null && LiveChild != null && previousCam != LiveChild)
            {
                // Create a blend (will be null if a cut)
                float duration = 0;
                var   curve    = LookupBlendCurve(previousCam, LiveChild, out duration);
                mActiveBlend = CreateBlend(
                    previousCam, LiveChild,
                    curve, duration, mActiveBlend, deltaTime);

                // Notify incoming camera of transition
                LiveChild.OnTransitionFromCamera(previousCam, worldUp, deltaTime);

                // Generate Camera Activation event if live
                CinemachineCore.Instance.GenerateCameraActivationEvent(LiveChild);

                // If cutting, generate a camera cut event if live
                if (mActiveBlend == null)
                {
                    CinemachineCore.Instance.GenerateCameraCutEvent(LiveChild);
                }
            }

            // Advance the current blend (if any)
            if (mActiveBlend != null)
            {
                mActiveBlend.TimeInBlend += deltaTime >= 0
                    ? deltaTime
                    : mActiveBlend.Duration;
                if (mActiveBlend.IsComplete)
                {
                    mActiveBlend = null;
                }
            }

            if (mActiveBlend != null)
            {
                mActiveBlend.UpdateCameraState(worldUp, deltaTime);
                m_State = mActiveBlend.State;
            }
            else if (LiveChild != null)
            {
                m_State = LiveChild.State;
            }

            PreviousStateIsValid = true;
            //UnityEngine.Profiling.Profiler.EndSample();
        }
        /// <summary>Called by CinemachineCore at designated update time
        /// so the vcam can position itself and track its targets.  This implementation
        /// updates all the children, chooses the best one, and implements any required blending.</summary>
        /// <param name="worldUp">Default world Up, set by the CinemachineBrain</param>
        /// <param name="deltaTime">Delta time for time-based effects (ignore if less than or equal to 0)</param>
        public override void UpdateCameraState(Vector3 worldUp, float deltaTime)
        {
            if (!PreviousStateIsValid)
            {
                deltaTime = -1;
            }
            PreviousStateIsValid = true;

            UpdateListOfChildren();
            CinemachineVirtualCameraBase best = ChooseCurrentCamera(deltaTime);

            if (m_ChildCameras != null)
            {
                foreach (CinemachineVirtualCameraBase vcam in m_ChildCameras)
                {
                    if (vcam != null)
                    {
                        vcam.gameObject.SetActive(m_EnableAllChildCameras || vcam == best);
                        if (vcam.VirtualCameraGameObject.activeInHierarchy)
                        {
                            vcam.AddPostPipelineStageHook(OnPostPipelineStage);
                            CinemachineCore.Instance.UpdateVirtualCamera(vcam, worldUp, deltaTime);
                        }
                    }
                }
            }

            ICinemachineCamera previousCam = LiveChild;

            LiveChild = best;

            // Are we transitioning cameras?
            if (previousCam != null && LiveChild != null && previousCam != LiveChild)
            {
                // Create a blend (will be null if a cut)
                mActiveBlend = CreateBlend(
                    previousCam, LiveChild,
                    LookupBlendCurve(previousCam, LiveChild),
                    mActiveBlend, deltaTime);

                // Notify incoming camera of transition
                LiveChild.OnTransitionFromCamera(previousCam);

                // Generate Camera Activation event if live
                CinemachineCore.Instance.GenerateCameraActivationEvent(LiveChild);

                // If cutting, generate a camera cut event if live
                if (mActiveBlend == null)
                {
                    CinemachineCore.Instance.GenerateCameraCutEvent(LiveChild);
                }
            }

            // Advance the current blend (if any)
            if (mActiveBlend != null)
            {
                mActiveBlend.TimeInBlend += (deltaTime > 0)
                    ? deltaTime : mActiveBlend.Duration;
                if (mActiveBlend.IsComplete)
                {
                    mActiveBlend = null;
                }
            }

            if (mActiveBlend != null)
            {
                mActiveBlend.UpdateCameraState(worldUp, deltaTime);
                m_State = mActiveBlend.State;
            }
            else if (LiveChild != null)
            {
                m_State = LiveChild.State;
            }

            // Push the raw position back to the game object's transform, so it
            // moves along with the camera.  Leave the orientation alone, because it
            // screws up camera dragging when there is a LookAt behaviour.
            if (Follow != null)
            {
                transform.position = State.RawPosition;
            }
        }
        /// <summary>Called by CinemachineCore at designated update time
        /// so the vcam can position itself and track its targets.  This implementation
        /// updates all the children, chooses the best one, and implements any required blending.</summary>
        /// <param name="worldUp">Default world Up, set by the CinemachineBrain</param>
        /// <param name="deltaTime">Delta time for time-based effects (ignore if less than or equal to 0)</param>
        public override void UpdateCameraState(Vector3 worldUp, float deltaTime)
        {
            //UnityEngine.Profiling.Profiler.BeginSample("CinemachineBlendListCamera.UpdateCameraState");
            if (!PreviousStateIsValid)
            {
                deltaTime = -1;
            }

            UpdateListOfChildren();

            AdvanceCurrentInstruction();
            CinemachineVirtualCameraBase best = null;

            if (mCurrentInstruction >= 0 && mCurrentInstruction < m_Instructions.Length)
            {
                best = m_Instructions[mCurrentInstruction].m_VirtualCamera;
            }

            if (m_ChildCameras != null)
            {
                for (int i = 0; i < m_ChildCameras.Length; ++i)
                {
                    CinemachineVirtualCameraBase vcam = m_ChildCameras[i];
                    if (vcam != null)
                    {
                        bool enableChild = m_EnableAllChildCameras || vcam == best;
                        if (enableChild != vcam.VirtualCameraGameObject.activeInHierarchy)
                        {
                            vcam.gameObject.SetActive(enableChild);
                            if (enableChild)
                            {
                                CinemachineCore.Instance.UpdateVirtualCamera(vcam, worldUp, deltaTime);
                            }
                        }
                    }
                }
            }

            if (best != null)
            {
                ICinemachineCamera previousCam = LiveChild;
                LiveChild = best;

                // Are we transitioning cameras?
                if (previousCam != null && LiveChild != null && previousCam != LiveChild && mCurrentInstruction > 0)
                {
                    // Create a blend (will be null if a cut)
                    mActiveBlend = CreateBlend(
                        previousCam, LiveChild,
                        m_Instructions[mCurrentInstruction].m_Blend.BlendCurve,
                        m_Instructions[mCurrentInstruction].m_Blend.m_Time, mActiveBlend, deltaTime);

                    // Notify incoming camera of transition
                    LiveChild.OnTransitionFromCamera(previousCam, worldUp, deltaTime);

                    // Generate Camera Activation event if live
                    CinemachineCore.Instance.GenerateCameraActivationEvent(LiveChild);

                    // If cutting, generate a camera cut event if live
                    if (mActiveBlend == null)
                    {
                        CinemachineCore.Instance.GenerateCameraCutEvent(LiveChild);
                    }
                }
            }

            // Advance the current blend (if any)
            if (mActiveBlend != null)
            {
                mActiveBlend.TimeInBlend += (deltaTime >= 0) ? deltaTime : mActiveBlend.Duration;
                if (mActiveBlend.IsComplete)
                {
                    mActiveBlend = null;
                }
            }

            if (mActiveBlend != null)
            {
                mActiveBlend.UpdateCameraState(worldUp, deltaTime);
                m_State = mActiveBlend.State;
            }
            else if (LiveChild != null)
            {
                m_State = LiveChild.State;
            }

            PreviousStateIsValid = true;
            //UnityEngine.Profiling.Profiler.EndSample();
        }