예제 #1
0
        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);
                }
            }
        }
예제 #2
0
        private void UpdateVirtualCameras(CinemachineCore.UpdateFilter updateFilter, float deltaTime)
        {
            // We always update all active virtual cameras
            CinemachineCore.Instance.CurrentUpdateFilter = updateFilter;
            Camera camera = OutputCamera;

            CinemachineCore.Instance.UpdateAllActiveVirtualCameras(
                camera == null ? -1 : camera.cullingMask, DefaultWorldUp, deltaTime);

            // Make sure all live cameras get updated, in case some of them are deactivated
            if (SoloCamera != null)
            {
                SoloCamera.UpdateCameraState(DefaultWorldUp, deltaTime);
            }
            mCurrentLiveCameras.UpdateCameraState(DefaultWorldUp, deltaTime);

            // Restore the filter for general use
            updateFilter = CinemachineCore.UpdateFilter.Late;
            if (Application.isPlaying)
            {
                if (m_UpdateMethod == UpdateMethod.SmartUpdate)
                {
                    updateFilter |= CinemachineCore.UpdateFilter.Smart;
                }
                else if (m_UpdateMethod == UpdateMethod.FixedUpdate)
                {
                    updateFilter = CinemachineCore.UpdateFilter.Fixed;
                }
            }
            CinemachineCore.Instance.CurrentUpdateFilter = updateFilter;
        }
예제 #3
0
        private void UpdateVirtualCameras(CinemachineCore.UpdateFilter updateFilter, float deltaTime)
        {
            CinemachineCore.Instance.CurrentUpdateFilter = updateFilter;

            // We always update all active virtual cameras in the priority stack
            foreach (ICinemachineCamera cam in CinemachineCore.Instance.AllCameras)
            {
                CinemachineCore.Instance.UpdateVirtualCamera(cam, DefaultWorldUp, deltaTime);
            }

            // Make sure that the active camera gets updated this frame.
            // Only cameras that are enabled and in the priority stack
            // get automatically updated.
            ICinemachineCamera vcam = ActiveVirtualCamera;

            if (vcam != null)
            {
                CinemachineCore.Instance.UpdateVirtualCamera(
                    vcam, DefaultWorldUp, deltaTime);
            }

            CinemachineBlend activeBlend = ActiveBlend;

            if (activeBlend != null)
            {
                activeBlend.UpdateCameraState(DefaultWorldUp, deltaTime);
            }
        }
예제 #4
0
        private void UpdateVirtualCameras(CinemachineCore.UpdateFilter updateFilter, float deltaTime)
        {
            //UnityEngine.Profiling.Profiler.BeginSample("CinemachineBrain.UpdateVirtualCameras");
            CinemachineCore.Instance.CurrentUpdateFilter = updateFilter;

            // We always update all active virtual cameras
            CinemachineCore.Instance.UpdateAllActiveVirtualCameras(DefaultWorldUp, deltaTime);

            // Make sure that the current live cameras get updated this frame.
            // Only cameras that are enabled get automatically updated.
            ICinemachineCamera vcam = ActiveVirtualCamera;

            if (vcam != null)
            {
                vcam.UpdateCameraState(DefaultWorldUp, deltaTime);
            }
            CinemachineBlend activeBlend = ActiveBlend;

            if (activeBlend != null)
            {
                activeBlend.UpdateCameraState(DefaultWorldUp, deltaTime);
            }

            // Restore the filter for general use
            CinemachineCore.Instance.CurrentUpdateFilter = CinemachineCore.UpdateFilter.Late;
            //UnityEngine.Profiling.Profiler.EndSample();
        }
예제 #5
0
        private void UpdateVirtualCameras(CinemachineCore.UpdateFilter updateFilter, float deltaTime)
        {
            // We always update all active virtual cameras
            CinemachineCore.Instance.CurrentUpdateFilter = updateFilter;
            Camera camera = OutputCamera;

            CinemachineCore.Instance.UpdateAllActiveVirtualCameras(
                camera == null ? -1 : camera.cullingMask, DefaultWorldUp, deltaTime);

            // Make sure that the current live cameras get updated this frame.
            // Only cameras that are enabled get automatically updated.
            ICinemachineCamera vcam = ActiveVirtualCamera;

            if (vcam != null)
            {
                vcam.UpdateCameraState(DefaultWorldUp, deltaTime);
            }
            CinemachineBlend activeBlend = ActiveBlend;

            if (activeBlend != null)
            {
                activeBlend.UpdateCameraState(DefaultWorldUp, deltaTime);
            }

            // Restore the filter for general use
            CinemachineCore.Instance.CurrentUpdateFilter = CinemachineCore.UpdateFilter.Late;
        }
예제 #6
0
        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);
        }
예제 #7
0
        private void UpdateVirtualCameras(CinemachineCore.UpdateFilter updateFilter, float deltaTime)
        {
            //UnityEngine.Profiling.Profiler.BeginSample("CinemachineBrain.UpdateVirtualCameras");
            CinemachineCore.Instance.CurrentUpdateFilter = updateFilter;

            // We always update all active virtual cameras in the priority stack
            foreach (ICinemachineCamera cam in CinemachineCore.Instance.AllCameras)
            {
                CinemachineCore.Instance.UpdateVirtualCamera(cam, DefaultWorldUp, deltaTime);
            }

            // Make sure that the active camera gets updated this frame.
            // Only cameras that are enabled and in the priority stack
            // get automatically updated.
            ICinemachineCamera vcam = ActiveVirtualCamera;

            if (vcam != null)
            {
                CinemachineCore.Instance.UpdateVirtualCamera(
                    vcam, DefaultWorldUp, deltaTime);
            }

            CinemachineBlend activeBlend = ActiveBlend;

            if (activeBlend != null)
            {
                activeBlend.UpdateCameraState(DefaultWorldUp, deltaTime);
            }

            // Restore the filter for general use
            CinemachineCore.Instance.CurrentUpdateFilter = CinemachineCore.UpdateFilter.Any;
            //UnityEngine.Profiling.Profiler.EndSample();
        }
        /// <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);
            }
        }
예제 #9
0
        private void UpdateVirtualCameras(CinemachineCore.UpdateFilter updateFilter, float deltaTime)
        {
            CinemachineCore.Instance.CurrentUpdateFilter = updateFilter;
            CinemachineCore.Instance.UpdateAllActiveVirtualCameras(this.DefaultWorldUp, deltaTime);
            ICinemachineCamera activeVirtualCamera = this.ActiveVirtualCamera;

            if (activeVirtualCamera != null)
            {
                CinemachineCore.Instance.UpdateVirtualCamera(activeVirtualCamera, this.DefaultWorldUp, deltaTime);
            }
            CinemachineBlend activeBlend = this.ActiveBlend;

            if (activeBlend != null)
            {
                activeBlend.UpdateCameraState(this.DefaultWorldUp, deltaTime);
            }
            CinemachineCore.Instance.CurrentUpdateFilter = CinemachineCore.UpdateFilter.Late;
        }
예제 #10
0
        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);
        }
예제 #11
0
        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));
                }
            }
        }
예제 #12
0
 public CinemachineCore.UpdateFilter ChoosePreferredUpdate(int currentFrame, Matrix4x4 pos, CinemachineCore.UpdateFilter updateFilter)
 {
     if (this.targetPos != pos)
     {
         if (updateFilter == CinemachineCore.UpdateFilter.Late)
         {
             this.numWindowLateUpdateMoves++;
         }
         else if (this.lastUpdateSubframe == 0)
         {
             this.numWindowFixedUpdateMoves++;
         }
         this.targetPos = pos;
     }
     CinemachineCore.UpdateFilter updateFilter2 = this.preferredUpdate;
     if ((this.numWindowLateUpdateMoves > 0 && this.numWindowFixedUpdateMoves > 0) || this.numWindowLateUpdateMoves >= this.numWindowFixedUpdateMoves)
     {
         updateFilter2 = CinemachineCore.UpdateFilter.Late;
     }
     else
     {
         updateFilter2 = CinemachineCore.UpdateFilter.Fixed;
     }
     if (this.numWindows == 0)
     {
         this.preferredUpdate = updateFilter2;
     }
     if (this.windowStart + 30 <= currentFrame)
     {
         this.preferredUpdate = updateFilter2;
         this.numWindows++;
         this.windowStart = currentFrame;
         this.numWindowLateUpdateMoves = (this.numWindowFixedUpdateMoves = 0);
     }
     return(this.preferredUpdate);
 }
예제 #13
0
        internal bool UpdateVirtualCamera(ICinemachineCamera vcam, Vector3 worldUp, float deltaTime)
        {
            int frameCount = Time.frameCount;

            CinemachineCore.UpdateFilter updateFilter = this.CurrentUpdateFilter;
            bool flag  = updateFilter != CinemachineCore.UpdateFilter.ForcedFixed && updateFilter != CinemachineCore.UpdateFilter.ForcedLate;
            bool flag2 = updateFilter == CinemachineCore.UpdateFilter.Late;

            if (!flag)
            {
                if (updateFilter == CinemachineCore.UpdateFilter.ForcedFixed)
                {
                    updateFilter = CinemachineCore.UpdateFilter.Fixed;
                }
                if (updateFilter == CinemachineCore.UpdateFilter.ForcedLate)
                {
                    updateFilter = CinemachineCore.UpdateFilter.Late;
                }
            }
            if (this.mUpdateStatus == null)
            {
                this.mUpdateStatus = new Dictionary <ICinemachineCamera, CinemachineCore.UpdateStatus>();
            }
            if (vcam.VirtualCameraGameObject == null)
            {
                if (this.mUpdateStatus.ContainsKey(vcam))
                {
                    this.mUpdateStatus.Remove(vcam);
                }
                return(false);
            }
            CinemachineCore.UpdateStatus updateStatus;
            if (!this.mUpdateStatus.TryGetValue(vcam, out updateStatus))
            {
                updateStatus = new CinemachineCore.UpdateStatus(frameCount);
                this.mUpdateStatus.Add(vcam, updateStatus);
            }
            int num = flag2 ? 1 : CinemachineBrain.GetSubframeCount();

            if (updateStatus.lastUpdateFrame != frameCount)
            {
                updateStatus.lastUpdateSubframe = 0;
            }
            bool flag3 = !flag;

            if (flag)
            {
                Matrix4x4 pos;
                if (!CinemachineCore.GetTargetPosition(vcam, out pos))
                {
                    flag3 = flag2;
                }
                else
                {
                    flag3 = (updateStatus.ChoosePreferredUpdate(frameCount, pos, updateFilter) == updateFilter);
                }
            }
            if (flag3)
            {
                updateStatus.preferredUpdate = updateFilter;
                while (updateStatus.lastUpdateSubframe < num)
                {
                    vcam.UpdateCameraState(worldUp, deltaTime);
                    updateStatus.lastUpdateSubframe++;
                }
                updateStatus.lastUpdateFrame = frameCount;
            }
            this.mUpdateStatus[vcam] = updateStatus;
            return(true);
        }
        protected void DrawCameraStatusInInspector()
        {
            // Is the camera navel-gazing?
            CameraState state = Target.State;

            if (state.HasLookAt && (state.ReferenceLookAt - state.CorrectedPosition).AlmostZero())
            {
                EditorGUILayout.HelpBox(
                    "The camera is positioned on the same point at which it is trying to look.",
                    MessageType.Warning);
            }

            // Active status and Solo button
            Rect rect      = EditorGUILayout.GetControlRect(true);
            Rect rectLabel = new Rect(rect.x, rect.y, EditorGUIUtility.labelWidth, rect.height);

            rect.width -= rectLabel.width;
            rect.x     += rectLabel.width;

            Color color  = GUI.color;
            bool  isSolo = (CinemachineBrain.SoloCamera == (ICinemachineCamera)Target);

            if (isSolo)
            {
                GUI.color = CinemachineBrain.GetSoloGUIColor();
            }

            bool isLive = CinemachineCore.Instance.IsLive(Target);

            GUI.enabled = isLive;
            GUI.Label(rectLabel, isLive ? "Status: Live"
                : (Target.isActiveAndEnabled ? "Status: Standby" : "Status: Disabled"));
            GUI.enabled = true;

            float      labelWidth = 0;
            GUIContent updateText = GUIContent.none;

            CinemachineCore.UpdateFilter updateMode = CinemachineCore.Instance.GetVcamUpdateStatus(Target);
            if (Application.isPlaying)
            {
                updateText = new GUIContent(
                    updateMode < CinemachineCore.UpdateFilter.Late ? " Fixed Update" : " Late Update");
                var textDimensions = GUI.skin.label.CalcSize(updateText);
                labelWidth = textDimensions.x;
            }
            rect.width -= labelWidth;
            if (GUI.Button(rect, "Solo", "Button"))
            {
                isSolo = !isSolo;
                CinemachineBrain.SoloCamera = isSolo ? Target : null;
                UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
            }
            GUI.color = color;
            if (isSolo)
            {
                UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
            }

            if (labelWidth > 0)
            {
                GUI.enabled = false;
                rect.x     += rect.width; rect.width = labelWidth;
                GUI.Label(rect, updateText);
                GUI.enabled = true;
            }
        }