Esempio n. 1
0
 /// <summary>See whether the virtual camera has been moved nby the collider</summary>
 /// <param name="vcam">The virtual camera in question.  This might be different from the
 /// virtual camera that owns the collider, in the event that the camera has children</param>
 /// <returns>True if the virtual camera has been displaced due to collision or
 /// target obstruction</returns>
 public bool CameraWasDisplaced(ICinemachineCamera vcam)
 {
     return(GetCameraDisplacementDistance(vcam) > 0);
 }
Esempio n. 2
0
 public bool IsLiveChild(ICinemachineCamera vcam, bool dominantChildOnly = false)
 {
     return(false);
 }
Esempio n. 3
0
 public bool IsLiveChild(ICinemachineCamera vcam, bool dominantChildOnly = false)
 {
     return(Blend != null && (vcam == Blend.CamA || vcam == Blend.CamB));
 }
Esempio n. 4
0
    // This function handles movement of the camera between 2D and 3D shots,
    // and the changing of projection mode
    void Shift(bool dim, float time)
    {
        // Assign global variables to values of event parameters
        dimension = dim;
        GetComponent <CinemachineBrain> ().m_DefaultBlend.m_Time = time;

        // if shifting to 3d...
        if (dim)
        {
            // switch to the freelook camera.
            MoveCamera(5);

            // Refers to the Matrixblender script to change perspective
            if (blendingOrtho)
            {
                blender.BlendToMatrix(pers, time);
            }
        }

        // else, if shifting to 2d...
        else
        {
            // if this is the very first time shift is called...
            if (startFlag)
            {
                // if the game starts in 2D, camera is moved by shotchange,
                // and we instantly blend to orthographic
                if (blendingOrtho)
                {
                    blender.BlendToMatrix(ortho, 0.001f);
                }
            }

            else
            {
                // Get the location of the freelook camera
                List <GameObject>  temp         = shot_reference.GetRange(0, 4);
                ICinemachineCamera locationtemp = GetComponent <CinemachineBrain> ().ActiveVirtualCamera;
                GameObject         location     = locationtemp.VirtualCameraGameObject;

                // iterate through the 4 2d shots, can move to the one closest to the freelook camera
                float shortest = Mathf.Infinity;
                float distance = 0;
                int   index    = 0;

                foreach (GameObject camera in temp)
                {
                    distance = Vector3.Distance(location.transform.position, camera.transform.position);
                    if (distance < shortest)
                    {
                        shortest = distance;
                        index    = temp.IndexOf(camera);
                    }
                }

                // trigger a shotchange event, which will in turn move the camera.
                if (world_controller)
                {
                    world_controller.ShotChangeOnExternalCall(index + 1);
                }


                // Refers to the Matrixblender script to change perspective
                if (blendingOrtho)
                {
                    blender.BlendToMatrix(ortho, time);
                }
            }
        }

        startFlag = false;
    }
Esempio n. 5
0
        private void ProcessActiveCamera(float deltaTime)
        {
            // This condition should never occur, but let's be defensive
            if ((OutputCamera == null) || !OutputCamera.isActiveAndEnabled)
            {
                mActiveCameraPreviousFrame   = null;
                mOutgoingCameraPreviousFrame = null;
                mPreviousFrameWasOverride    = false;
                return;
            }

            //UnityEngine.Profiling.Profiler.BeginSample("Cinemachine");
            OverrideStackFrame activeOverride = GetActiveOverride();
            ICinemachineCamera activeCamera   = ActiveVirtualCamera;

            if (activeCamera == null)
            {
                mOutgoingCameraPreviousFrame = null;
            }
            else
            {
                // If there is an override, we kill the in-game blend
                if (activeOverride != null)
                {
                    mActiveBlend = null;
                }
                CinemachineBlend activeBlend = ActiveBlend;

                // Are we transitioning cameras?
                if (mActiveCameraPreviousFrame != activeCamera)
                {
                    // Do we need to create a game-play blend?
                    if (mActiveCameraPreviousFrame != null &&
                        !mPreviousFrameWasOverride &&
                        activeOverride == null &&
                        deltaTime > 0)
                    {
                        // Create a blend (will be null if a cut)
                        activeBlend = CreateBlend(
                            mActiveCameraPreviousFrame, activeCamera,
                            LookupBlendCurve(mActiveCameraPreviousFrame, activeCamera),
                            mActiveBlend);
                    }
                    // Need this check because Timeline override sometimes inverts outgoing and incoming
                    if (activeCamera != mOutgoingCameraPreviousFrame)
                    {
                        // Notify incoming camera of transition
                        activeCamera.OnTransitionFromCamera(mActiveCameraPreviousFrame);
                        if (m_CameraActivatedEvent != null)
                        {
                            m_CameraActivatedEvent.Invoke();
                        }
                    }
                    // If we're cutting without a blend, or no active cameras
                    // were active last frame, send an event
                    if (activeBlend == null ||
                        (activeBlend.CamA != mActiveCameraPreviousFrame &&
                         activeBlend.CamB != mActiveCameraPreviousFrame &&
                         activeBlend.CamA != mOutgoingCameraPreviousFrame &&
                         activeBlend.CamB != mOutgoingCameraPreviousFrame))
                    {
                        if (m_CameraCutEvent != null)
                        {
                            m_CameraCutEvent.Invoke();
                        }
                    }
                }

                // Advance the current blend (if any)
                if (activeBlend != null)
                {
                    if (activeOverride == null)
                    {
                        activeBlend.TimeInBlend += (deltaTime > 0)
                            ? deltaTime : activeBlend.Duration;
                    }
                    if (activeBlend.IsComplete)
                    {
                        activeBlend = null;
                    }
                }
                if (activeOverride == null)
                {
                    mActiveBlend = activeBlend;
                }

                // Apply the result to the Unity camera
                if (!IsSuspended)
                {
                    CameraState state = activeCamera.State;
                    if (activeBlend != null)
                    {
                        state = activeBlend.State;
                    }
                    PushStateToUnityCamera(state, OutputCamera, activeCamera);
                }

                if (CoreDebuggerPostFrameUpdateCallback != null)
                {
                    CoreDebuggerPostFrameUpdateCallback();
                }

                mOutgoingCameraPreviousFrame = null;
                if (activeBlend != null)
                {
                    mOutgoingCameraPreviousFrame = activeBlend.CamB;
                }
            }
            mActiveCameraPreviousFrame = activeCamera;
            mPreviousFrameWasOverride  = (activeOverride != null);
            if (mPreviousFrameWasOverride)
            {
                // Because we don't know whether blending in or out... grrr...
                if (activeOverride.blend != null)
                {
                    if (activeOverride.blend.BlendWeight < 0.5f)
                    {
                        mActiveCameraPreviousFrame   = activeOverride.blend.CamA;
                        mOutgoingCameraPreviousFrame = activeOverride.blend.CamB;
                    }
                    else
                    {
                        mActiveCameraPreviousFrame   = activeOverride.blend.CamB;
                        mOutgoingCameraPreviousFrame = activeOverride.blend.CamA;
                    }
                }
            }
            //UnityEngine.Profiling.Profiler.EndSample();
        }
 private static string GetCameraDebugFilePath(ICinemachineCamera vCam)
 {
     return(string.Format("{0}_debug.csv", vCam.Name));
 }
Esempio n. 7
0
 /// <summary>See whether the virtual camera has been moved nby the collider</summary>
 /// <param name="vcam">The virtual camera in question.  This might be different from the
 /// virtual camera that owns the collider, in the event that the camera has children</param>
 /// <returns>True if the virtual camera has been displaced due to collision or
 /// target obstruction</returns>
 public bool CameraWasDisplaced(ICinemachineCamera vcam)
 {
     return(GetExtraState <VcamExtraState>(vcam).colliderDisplacement > 0);
 }
 /// <summary>Notification that this virtual camera is going live.
 /// Base class implementation does nothing.</summary>
 /// <param name="fromCam">The camera being deactivated.  May be null.</param>
 /// <param name="worldUp">Default world Up, set by the CinemachineBrain</param>
 /// <param name="deltaTime">Delta time for time-based effects (ignore if less than or equal to 0)</param>
 /// <returns>True if the vcam should do an internal update as a result of this call</returns>
 public virtual bool OnTransitionFromCamera(
     ICinemachineCamera fromCam, Vector3 worldUp, float deltaTime,
     ref CinemachineVirtualCameraBase.TransitionParams transitionParams)
 {
     return(false);
 }
        /// <summary>Called by CinemachineCore at designated update time
        /// so the vcam can position itself and track its targets.  This implementation
        /// updates all the children, chooses the best one, and implements any required blending.</summary>
        /// <param name="worldUp">Default world Up, set by the CinemachineBrain</param>
        /// <param name="deltaTime">Delta time for time-based effects (ignore if less than or equal to 0)</param>
        public override void UpdateCameraState(Vector3 worldUp, float deltaTime)
        {
            //UnityEngine.Profiling.Profiler.BeginSample("CinemachineStateDrivenCamera.UpdateCameraState");
            if (!PreviousStateIsValid)
            {
                deltaTime = -1;
            }

            UpdateListOfChildren();
            CinemachineVirtualCameraBase best = ChooseCurrentCamera(deltaTime);

            if (m_ChildCameras != null)
            {
                for (int i = 0; i < m_ChildCameras.Length; ++i)
                {
                    CinemachineVirtualCameraBase vcam = m_ChildCameras[i];
                    if (vcam != null)
                    {
                        bool enableChild = m_EnableAllChildCameras || vcam == best;
                        if (enableChild != vcam.VirtualCameraGameObject.activeInHierarchy)
                        {
                            vcam.gameObject.SetActive(enableChild);
                            if (enableChild)
                            {
                                CinemachineCore.Instance.UpdateVirtualCamera(vcam, worldUp, deltaTime);
                            }
                        }
                    }
                }
            }

            ICinemachineCamera previousCam = LiveChild;

            LiveChild = best;

            // Are we transitioning cameras?
            if (previousCam != null && LiveChild != null && previousCam != LiveChild)
            {
                // Create a blend (will be null if a cut)
                float          duration = 0;
                AnimationCurve curve    = LookupBlendCurve(previousCam, LiveChild, out duration);
                mActiveBlend = CreateBlend(
                    previousCam, LiveChild,
                    curve, duration, mActiveBlend, deltaTime);

                // Notify incoming camera of transition
                LiveChild.OnTransitionFromCamera(previousCam, worldUp, deltaTime);

                // Generate Camera Activation event if live
                CinemachineCore.Instance.GenerateCameraActivationEvent(LiveChild);

                // If cutting, generate a camera cut event if live
                if (mActiveBlend == null)
                {
                    CinemachineCore.Instance.GenerateCameraCutEvent(LiveChild);
                }
            }

            // Advance the current blend (if any)
            if (mActiveBlend != null)
            {
                mActiveBlend.TimeInBlend += (deltaTime >= 0)
                    ? deltaTime : mActiveBlend.Duration;
                if (mActiveBlend.IsComplete)
                {
                    mActiveBlend = null;
                }
            }

            if (mActiveBlend != null)
            {
                mActiveBlend.UpdateCameraState(worldUp, deltaTime);
                m_State = mActiveBlend.State;
            }
            else if (LiveChild != null)
            {
                m_State = LiveChild.State;
            }

            PreviousStateIsValid = true;
            //UnityEngine.Profiling.Profiler.EndSample();
        }
 /// <summary>Check whether the vcam a live child of this camera.</summary>
 /// <param name="vcam">The Virtual Camera to check</param>
 /// <returns>True if the vcam is currently actively influencing the state of this vcam</returns>
 public override bool IsLiveChild(ICinemachineCamera vcam)
 {
     return(vcam == LiveChild ||
            (mActiveBlend != null && (vcam == mActiveBlend.CamA || vcam == mActiveBlend.CamB)));
 }
    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));
    }
Esempio n. 12
0
 /// <summary>Notification that this virtual camera is going live.
 /// Base class implementation must be called by any overridden method.</summary>
 /// <param name="fromCam">The camera being deactivated.  May be null.</param>
 /// <param name="worldUp">Default world Up, set by the CinemachineBrain</param>
 /// <param name="deltaTime">Delta time for time-based effects (ignore if less than or equal to 0)</param>
 /// <returns>True to request a vcam update of internal state</returns>
 public virtual bool OnTransitionFromCamera(
     ICinemachineCamera fromCam, Vector3 worldUp, float deltaTime)
 {
     return(false);
 }