// CinemachineBrain callback used when this behaviour is on the Unity Camera
 bool PostFXHandler(Camera dest, ICinemachineCamera vcam, CameraState state)
 {
     if (enabled && mBrain != null && mPostProcessingBehaviour != null)
     {
         // Look for the vcam's PostFX behaviour
         CinemachinePostFX postFX = (vcam == null) ? this : GetEffectivePstFX(vcam);
         if (postFX != null)
         {
             if (postFX.m_Profile != null)
             {
                 // Adjust the focus distance
                 UnityEngine.PostProcessing.DepthOfFieldModel.Settings dof
                     = postFX.m_Profile.depthOfField.settings;
                 if (postFX.m_FocusTracksTarget && state.HasLookAt)
                 {
                     dof.focusDistance = (state.FinalPosition - state.ReferenceLookAt).magnitude
                                         + postFX.m_FocusOffset;
                 }
                 postFX.m_Profile.depthOfField.settings = dof;
             }
             // Apply the profile
             if (mPostProcessingBehaviour.profile != postFX.m_Profile)
             {
                 mPostProcessingBehaviour.profile = postFX.m_Profile;
                 mPostProcessingBehaviour.ResetTemporalEffects();
             }
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        // CinemachineBrain callback used when this behaviour is on the Unity Camera
        internal void PostFXHandler(CinemachineBrain brain)
        {
            //UnityEngine.Profiling.Profiler.BeginSample("CinemachinePostFX.PostFXHandler");
            ICinemachineCamera vcam = brain.ActiveVirtualCamera;

            if (enabled && mBrain != null && mPostProcessingBehaviour != null)
            {
                // Look for the vcam's PostFX behaviour
                CinemachinePostFX postFX = GetEffectivePostFX(vcam);
                if (postFX == null)
                {
                    postFX = this;  // vcam does not define a profile - apply the default
                }
                if (postFX.m_Profile != null)
                {
                    // Adjust the focus distance
                    CameraState state = brain.CurrentCameraState;
                    UnityEngine.PostProcessing.DepthOfFieldModel.Settings dof
                        = postFX.m_Profile.depthOfField.settings;
                    if (postFX.m_FocusTracksTarget && state.HasLookAt)
                    {
                        dof.focusDistance = (state.FinalPosition - state.ReferenceLookAt).magnitude
                                            + postFX.m_FocusOffset;
                    }
                    postFX.m_Profile.depthOfField.settings = dof;
                }
                // Apply the profile
                if (mPostProcessingBehaviour.profile != postFX.m_Profile)
                {
                    mPostProcessingBehaviour.profile = postFX.m_Profile;
                    mPostProcessingBehaviour.ResetTemporalEffects();
                }
            }
            //UnityEngine.Profiling.Profiler.EndSample();
        }
Exemplo n.º 3
0
        static void StaticPostFXHandler(CinemachineBrain brain)
        {
            CinemachinePostFX postFX = brain.PostProcessingComponent as CinemachinePostFX;

            if (postFX == null)
            {
                brain.PostProcessingComponent = brain.GetComponent <CinemachinePostFX>();
                postFX = brain.PostProcessingComponent as CinemachinePostFX;
                if (postFX != null)
                {
                    postFX.ConnectToBrain();
                }
            }
            if (postFX != null)
            {
                postFX.PostFXHandler(brain);
            }
        }
        CinemachinePostFX GetEffectivePstFX(ICinemachineCamera vcam)
        {
            while (vcam != null && vcam.LiveChildOrSelf != vcam)
            {
                vcam = vcam.LiveChildOrSelf;
            }
            CinemachinePostFX postFX = null;

            while (vcam != null && postFX == null)
            {
                postFX = vcam.VirtualCameraGameObject.GetComponent <CinemachinePostFX>();
                if (postFX != null && !postFX.enabled)
                {
                    postFX = null;
                }
                vcam = vcam.ParentCamera;
            }
            return(postFX);
        }
Exemplo n.º 5
0
            static EditorInitialize()
            {
#if UNITY_POST_PROCESSING_STACK_V2
                // We have PPv2
                CinemachinePostProcessing.InitializeModule();
#else
                // Check for PostProcessing V1.  Define symbol if we have it.
                if (ReflectionHelpers.TypeIsDefined("UnityEngine.PostProcessing.PostProcessingBehaviour"))
                {
                    if (Cinemachine.Editor.ScriptableObjectUtility.AddDefineForAllBuildTargets("UNITY_POST_PROCESSING_STACK_V1"))
                    {
                        string path = Cinemachine.Editor.ScriptableObjectUtility.CinemachineInstallAssetPath + "/PostFX/CinemachinePostFX.cs";
                        UnityEditor.AssetDatabase.ImportAsset(path, UnityEditor.ImportAssetOptions.ForceUpdate);
                    }
                }
    #if UNITY_POST_PROCESSING_STACK_V1
                // We have PPv1
                CinemachinePostFX.InitializeModule();
    #endif
#endif
            }