Esempio n. 1
0
        public override void ProcessFrame(Playable playable, FrameData info, object playerData)
        {
            base.ProcessFrame(playable, info, playerData);
            GameObject gameObject = playerData as GameObject;

            if (gameObject == null)
            {
                this.mBrain = (CinemachineBrain)playerData;
            }
            else
            {
                this.mBrain = gameObject.GetComponent <CinemachineBrain>();
            }
            if (this.mBrain == null)
            {
                return;
            }
            int num = 0;
            ICinemachineCamera cinemachineCamera = null;
            ICinemachineCamera camA = null;
            float weightB           = 1f;

            for (int i = 0; i < playable.GetInputCount <Playable>(); i++)
            {
                CinemachineShotPlayable behaviour = ((ScriptPlayable <T>)playable.GetInput(i)).GetBehaviour();
                float inputWeight = playable.GetInputWeight(i);
                if (behaviour != null && behaviour.VirtualCamera != null && playable.GetPlayState <Playable>() == PlayState.Playing && inputWeight > 0.0001f)
                {
                    if (num == 1)
                    {
                        camA = cinemachineCamera;
                    }
                    weightB           = inputWeight;
                    cinemachineCamera = behaviour.VirtualCamera;
                    num++;
                    if (num == 2)
                    {
                        break;
                    }
                }
            }
            float deltaTime = info.deltaTime;

            if (!this.mPlaying)
            {
                if (this.mBrainOverrideId < 0)
                {
                    this.mLastOverrideFrame = -1f;
                }
                float realtimeSinceStartup = Time.realtimeSinceStartup;
                deltaTime = Time.unscaledDeltaTime;
                if (!Application.isPlaying && (this.mLastOverrideFrame < 0f || realtimeSinceStartup - this.mLastOverrideFrame > Time.maximumDeltaTime))
                {
                    deltaTime = -1f;
                }
                this.mLastOverrideFrame = realtimeSinceStartup;
            }
            this.mBrainOverrideId = this.mBrain.SetCameraOverride(this.mBrainOverrideId, camA, cinemachineCamera, weightB, deltaTime);
        }
Esempio n. 2
0
        public override void ProcessFrame(Playable playable, FrameData info, object playerData)
        {
            base.ProcessFrame(playable, info, playerData);

            // Get the brain that this track controls.
            // Older versions of timeline sent the gameObject by mistake.
            GameObject go = playerData as GameObject;

            if (go == null)
            {
                mBrain = (CinemachineBrain)playerData;
            }
            else
            {
                mBrain = go.GetComponent <CinemachineBrain>();
            }
            if (mBrain == null)
            {
                return;
            }

            // Find which clips are active.  We can process a maximum of 2.
            // In the case that the weights don't add up to 1, the outgoing weight
            // will be calculated as the inverse of the incoming weight.
            int activeInputs        = 0;
            ICinemachineCamera camA = null;
            ICinemachineCamera camB = null;
            float camWeightB        = 1f;

            for (int i = 0; i < playable.GetInputCount(); ++i)
            {
                CinemachineShotPlayable shot
                    = ((ScriptPlayable <CinemachineShotPlayable>)playable.GetInput(i)).GetBehaviour();
                float weight = playable.GetInputWeight(i);
                if (shot != null && shot.IsValid &&
                    playable.GetPlayState() == PlayState.Playing &&
                    weight > 0.0001f)
                {
                    if (shot.VirtualCamera != null)
                    {
                        camA       = camB;
                        camWeightB = weight;
                        camB       = shot.VirtualCamera;
                    }
                    if (++activeInputs == 2)
                    {
                        break;
                    }
                }
            }

            // Override the Cinemachine brain with our results
            mBrainOverrideId = mBrain.SetCameraOverride(
                mBrainOverrideId, camA, camB, camWeightB, GetDeltaTime(info.deltaTime));
        }
        public override void ProcessFrame(Playable playable, FrameData info, object playerData)
        {
            base.ProcessFrame(playable, info, playerData);

            // Get the brain that this track controls.
            // Older versions of timeline sent the gameObject by mistake.
            GameObject go = playerData as GameObject;

            if (go == null)
            {
                mBrain = (CinemachineBrain)playerData;
            }
            else
            {
                mBrain = go.GetComponent <CinemachineBrain>();
            }
            if (mBrain == null)
            {
                return;
            }

            // Find which clips are active.  We can process a maximum of 2.
            // In the case that the weights don't add up to 1, the outgoing weight
            // will be calculated as the inverse of the incoming weight.
            int      activeInputs = 0;
            ClipInfo clipA        = new ClipInfo();
            ClipInfo clipB        = new ClipInfo();

            for (int i = 0; i < playable.GetInputCount(); ++i)
            {
                float weight = playable.GetInputWeight(i);
                var   clip   = (ScriptPlayable <CinemachineShotPlayable>)playable.GetInput(i);
                CinemachineShotPlayable shot = clip.GetBehaviour();
                if (shot != null && shot.IsValid &&
                    playable.GetPlayState() == PlayState.Playing &&
                    weight > 0)
                {
                    clipA           = clipB;
                    clipB.vcam      = shot.VirtualCamera;
                    clipB.weight    = weight;
                    clipB.localTime = clip.GetTime();
                    clipB.duration  = clip.GetDuration();
                    if (++activeInputs == 2)
                    {
                        break;
                    }
                }
            }

            // Figure out which clip is incoming
            bool incomingIsB = clipB.weight >= 1 || clipB.localTime < clipB.duration / 2;

            if (activeInputs == 2)
            {
                if (clipB.localTime < clipA.localTime)
                {
                    incomingIsB = true;
                }
                else if (clipB.localTime > clipA.localTime)
                {
                    incomingIsB = false;
                }
                else
                {
                    incomingIsB = clipB.duration >= clipA.duration;
                }
            }

            // Override the Cinemachine brain with our results
            ICinemachineCamera camA = incomingIsB ? clipA.vcam : clipB.vcam;
            ICinemachineCamera camB = incomingIsB ? clipB.vcam : clipA.vcam;
            float camWeightB        = incomingIsB ? clipB.weight : 1 - clipB.weight;

            mBrainOverrideId = mBrain.SetCameraOverride(
                mBrainOverrideId, camA, camB, camWeightB, GetDeltaTime(info.deltaTime));
        }