Ejemplo n.º 1
0
        public override void ProcessFrame(Playable playable, FrameData info, object playerData)
        {
            base.ProcessFrame(playable, info, playerData);

            if (MainCamera == null)
            {
                return;
            }

            int      activeInputs   = 0;
            ClipInfo clipA          = new ClipInfo();
            ClipInfo clipB          = new ClipInfo();
            float    shakeIntensity = 0f;

            for (int i = 0; i < playable.GetInputCount(); ++i)
            {
                float weight = playable.GetInputWeight(i);
                ScriptPlayable <MainCameraPlayableBehaviour> clip = (ScriptPlayable <MainCameraPlayableBehaviour>)playable.GetInput(i);

                MainCameraPlayableBehaviour shot = clip.GetBehaviour();

                if (shot != null)
                {
                    callCustomEvents = shot.callCustomEvents;
                }

                if (shot != null &&
                    shot.IsValid &&
                    playable.GetPlayState() == PlayState.Playing &&
                    weight > 0.0001f)
                {
                    clipA = clipB;

                    clipB.camera         = shot.gameCamera;
                    clipB.weight         = weight;
                    clipB.localTime      = clip.GetTime();
                    clipB.duration       = clip.GetDuration();
                    clipB.shakeIntensity = shot.shakeIntensity;

                    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;
                }
            }

            shakeIntensity = incomingIsB ? clipB.shakeIntensity : clipA.shakeIntensity;

            _Camera cameraA    = incomingIsB ? clipA.camera : clipB.camera;
            _Camera cameraB    = incomingIsB ? clipB.camera : clipA.camera;
            float   camWeightB = incomingIsB ? clipB.weight : 1 - clipB.weight;

            if (cameraB == null)
            {
                cameraB    = cameraA;
                cameraA    = null;
                camWeightB = 1f - camWeightB;
            }

            if (incomingIsB)
            {
                shakeIntensity = (clipA.shakeIntensity * (1f - camWeightB)) + (clipB.shakeIntensity * camWeightB);
            }
            else
            {
                shakeIntensity = (clipB.shakeIntensity * (1f - camWeightB)) + (clipA.shakeIntensity * camWeightB);
            }

            MainCamera.SetTimelineOverride(cameraA, cameraB, camWeightB, shakeIntensity);

            if (callCustomEvents)
            {
                _Camera thisFrameCamera = (incomingIsB) ? cameraB : cameraA;
                if (thisFrameCamera != lastFrameCamera)
                {
                    KickStarter.eventManager.Call_OnSwitchCamera(lastFrameCamera, thisFrameCamera, 0f);
                    lastFrameCamera = thisFrameCamera;
                }
            }
        }
        public override void ProcessFrame(Playable playable, FrameData info, object playerData)
        {
            base.ProcessFrame(playable, info, playerData);

            if (MainCamera == null)
            {
                return;
            }

            int      activeInputs = 0;
            ClipInfo clipA        = new ClipInfo();
            ClipInfo clipB        = new ClipInfo();

            for (int i = 0; i < playable.GetInputCount(); ++i)
            {
                float weight = playable.GetInputWeight(i);
                ScriptPlayable <MainCameraPlayableBehaviour> clip = (ScriptPlayable <MainCameraPlayableBehaviour>)playable.GetInput(i);

                MainCameraPlayableBehaviour shot = clip.GetBehaviour();
                if (shot != null &&
                    shot.IsValid &&
                    playable.GetPlayState() == PlayState.Playing &&
                    weight > 0.0001f)
                {
                    clipA           = clipB;
                    clipB.camera    = shot.gameCamera;
                    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;
                }
            }

            _Camera cameraA    = incomingIsB ? clipA.camera : clipB.camera;
            _Camera cameraB    = incomingIsB ? clipB.camera : clipA.camera;
            float   camWeightB = incomingIsB ? clipB.weight : 1 - clipB.weight;

            if (cameraB == null)
            {
                cameraB    = cameraA;
                cameraA    = null;
                camWeightB = 1f - camWeightB;
            }

            MainCamera.SetTimelineOverride(cameraA, cameraB, camWeightB);
        }