Beispiel #1
0
        /// <summary>
        /// Update a single Cinemachine Virtual Camera if and only if it
        /// hasn't already been updated this frame.  Always update vcams via this method.
        /// Calling this more than once per frame for the same camera will have no effect.
        /// </summary>
        internal bool UpdateVirtualCamera(ICinemachineCamera vcam, Vector3 worldUp, float deltaTime)
        {
            //UnityEngine.Profiling.Profiler.BeginSample("CinemachineCore.UpdateVirtualCamera");
            int          now           = Time.frameCount;
            UpdateFilter filter        = CurrentUpdateFilter;
            bool         isSmartUpdate = filter != UpdateFilter.ForcedFixed &&
                                         filter != UpdateFilter.ForcedLate;
            bool isSmartLateUpdate = filter == UpdateFilter.Late;

            if (!isSmartUpdate)
            {
                if (filter == UpdateFilter.ForcedFixed)
                {
                    filter = UpdateFilter.Fixed;
                }
                if (filter == UpdateFilter.ForcedLate)
                {
                    filter = UpdateFilter.Late;
                }
            }

            if (mUpdateStatus == null)
            {
                mUpdateStatus = new Dictionary <ICinemachineCamera, UpdateStatus>();
            }
            if (vcam.VirtualCameraGameObject == null)
            {
                if (mUpdateStatus.ContainsKey(vcam))
                {
                    mUpdateStatus.Remove(vcam);
                }
                //UnityEngine.Profiling.Profiler.EndSample();
                return(false); // camera was deleted
            }
            UpdateStatus status;

            if (!mUpdateStatus.TryGetValue(vcam, out status))
            {
                status = new UpdateStatus(now);
                mUpdateStatus.Add(vcam, status);
            }

            int subframes = isSmartLateUpdate ? 1 : CinemachineBrain.GetSubframeCount();

            if (status.lastUpdateFrame != now)
            {
                status.lastUpdateSubframe = 0;
            }

            // If we're in smart update mode and the target moved, then we must examine
            // how the target has been moving recently in order to figure out whether to
            // update now
            bool updateNow = !isSmartUpdate;

            if (isSmartUpdate)
            {
                Matrix4x4 targetPos;
                if (!GetTargetPosition(vcam, out targetPos))
                {
                    updateNow = isSmartLateUpdate; // no target
                }
                else
                {
                    updateNow = status.ChoosePreferredUpdate(now, targetPos, filter)
                                == filter;
                }
            }

            if (updateNow)
            {
                status.preferredUpdate = filter;
                while (status.lastUpdateSubframe < subframes)
                {
//Debug.Log(vcam.Name + ": frame " + Time.frameCount + "." + status.lastUpdateSubframe + ", " + CurrentUpdateFilter + ", deltaTime = " + deltaTime);
                    vcam.UpdateCameraState(worldUp, deltaTime);
                    ++status.lastUpdateSubframe;
                }
                status.lastUpdateFrame = now;
            }

            mUpdateStatus[vcam] = status;
            //UnityEngine.Profiling.Profiler.EndSample();
            return(true);
        }