예제 #1
0
        public void ScrubToHere(
            float currentTime, TargetPositionCache.Mode cacheMode, CinemachineBrain brain)
        {
            if (brain == null)
            {
                return;
            }
            TargetPositionCache.CacheMode   = cacheMode;
            TargetPositionCache.CurrentTime = currentTime;
            if (cacheMode != TargetPositionCache.Mode.Playback)
            {
                return;
            }

            float stepSize = TargetPositionCache.CacheStepSize;

            var up        = brain.DefaultWorldUp;
            var endTime   = TargetPositionCache.CurrentTime;
            var startTime = Mathf.Max(
                TargetPositionCache.CacheTimeRange.Start, endTime - GetMaxDampTime());
            var numSteps = Mathf.FloorToInt((endTime - startTime) / stepSize);

            for (int step = numSteps; step >= 0; --step)
            {
                var t = Mathf.Max(startTime, endTime - step * stepSize);
                TargetPositionCache.CurrentTime = t;
                var deltaTime = (step == numSteps) ? -1
                        : (t - startTime < stepSize ? t - startTime : stepSize);

                // Update all relevant vcams, leaf-most first
                for (int i = mAllCamerasForScrubbing.Count - 1; i >= 0; --i)
                {
                    var sublist = mAllCamerasForScrubbing[i];
                    for (int j = sublist.Count - 1; j >= 0; --j)
                    {
                        var vcam = sublist[j];
                        vcam.InternalUpdateCameraState(up, deltaTime);
                        if (deltaTime < 0)
                        {
                            vcam.ForceCameraPosition(
                                TargetPositionCache.GetTargetPosition(vcam.transform),
                                TargetPositionCache.GetTargetRotation(vcam.transform));
                        }
                    }
                }
            }
        }
예제 #2
0
        public void ScrubToHere(float currentTime, int playableIndex, bool isCut, float timeInClip, Vector3 up)
        {
            TargetPositionCache.CurrentTime = currentTime;

            if (TargetPositionCache.CacheMode == TargetPositionCache.Mode.Record)
            {
                // If the clip is newly activated, force the time to clip start,
                // in case timeline skipped some frames.  This will avoid target lerps between shots.
                if (Time.frameCount != TargetPositionCache.CurrentFrame)
                {
                    TargetPositionCache.IsCameraCut = false;
                }
                TargetPositionCache.CurrentFrame = Time.frameCount;
                if (isCut)
                {
                    TargetPositionCache.IsCameraCut = true;
                }

                return;
            }

            if (!TargetPositionCache.HasCurrentTime)
            {
                return;
            }

            var   cs       = CachedObjects[playableIndex];
            float stepSize = TargetPositionCache.CacheStepSize;

            // Impose upper limit on damping time, to avoid simulating too many frames
            float maxDampTime = Mathf.Max(0, timeInClip - stepSize);

            maxDampTime = Mathf.Min(cs.MaxDampTime, Mathf.Min(maxDampTime, 4.0f));

            var endTime   = TargetPositionCache.CurrentTime;
            var startTime = Mathf.Max(
                TargetPositionCache.CacheTimeRange.Start + stepSize, endTime - maxDampTime);
            var numSteps = Mathf.FloorToInt((endTime - startTime) / stepSize);

            for (int step = numSteps; step >= 0; --step)
            {
                var t = Mathf.Max(startTime, endTime - step * stepSize);
                TargetPositionCache.CurrentTime = t;
                var deltaTime = (step == numSteps) ? -1
                        : (t - startTime < stepSize ? t - startTime : stepSize);

                // Update all relevant vcams, leaf-most first
                for (int i = cs.Cameras.Count - 1; i >= 0; --i)
                {
                    var sublist = cs.Cameras[i];
                    for (int j = sublist.Count - 1; j >= 0; --j)
                    {
                        var vcam = sublist[j];
                        if (deltaTime < 0)
                        {
                            vcam.ForceCameraPosition(
                                TargetPositionCache.GetTargetPosition(vcam.transform),
                                TargetPositionCache.GetTargetRotation(vcam.transform));
                        }
                        vcam.InternalUpdateCameraState(up, deltaTime);
                    }
                }
            }
        }