internal void RemoveEffect(PostProcessingBase effect)
 {
     if (!TryRemoveEffect(effect))
     {
         Debug.LogErrorFormat("PostProcessingBase.TryRemoveEffectFromCamera({0}, {1}) failed", camera.name, effect.effectName);
     }
 }
        internal bool TryRemoveEffect(PostProcessingBase effect)
        {
            RemoveAllCommandBuffers(effect);
            var effects = GetEffects(camera);

            if (effects != null)
            {
                if (effects.ContainsKey(effect.GetType()))
                {
                    var wasSuccessfull = effects.Remove(effect.GetType());
                    OnEffectsChanged();
                }
                if (effects.Count == 0)
                {
                    m_CameraPostProcessingEffects.Remove(camera);
                }
            }
            return(true);            // JCO@@@ TODO: TryRemoveEffectFromCamera return value!!! TUT
        }
        internal void AddEffect(PostProcessingBase effect)
        {
            // Get Effects of camera
            // if camera doesn't have this effectType: add it. else throw exception?
            //
            var effects = GetEffects(camera);

            if (effects == null)
            {
                effects = new Dictionary <Type, PostProcessingBase>();
                m_CameraPostProcessingEffects.Add(camera, effects);
            }
            if (!effects.ContainsKey(effect.GetType()))
            {
                effects.Add(effect.GetType(), effect);
                OnEffectsChanged();
            }
            effect.InitializeEffect();
        }
        internal void RegisterCommandBuffer(PostProcessingBase effect, CameraEvent cameraEvent, CommandBuffer cb)
        {
            var cbs = GetCommandBuffers(camera);

            if (cbs == null)
            {
                cbs = new Dictionary <Tuple <Type, CameraEvent>, CommandBuffer>();
                m_CameraCommandBuffers.Add(camera, cbs);
            }

            var key = new Tuple <Type, CameraEvent>(effect.GetType(), cameraEvent);

            if (cbs.ContainsKey(key))
            {
                Debug.LogErrorFormat("Camera '{0}' already contains CommandBuffer for ({1}, {2}). Removing old buffer and adding new one", camera, effect.GetType().Name, cameraEvent);
                RemoveCommandBuffer(effect, cameraEvent, cb);
            }
            cbs[key] = cb;
            UpdateCameraCommandBuffers();
        }
        internal void RemoveAllCommandBuffers(PostProcessingBase effect)
        {
            var cbs = GetCommandBuffers(camera);

            if (cbs == null)
            {
                                #if UNITY_DEBUG && DEBUG_OUTPUT_VERBIOUS
                Debug.LogFormat("Camera '{0}' was not registered while trying to remove all CommandBuffers for {1}", camera, effect.GetType().Name);
                                #endif
                return;
            }

            foreach (var s in cbs.Where(kv => kv.Key.item1 == effect.GetType()).ToList())
            {
                camera.RemoveCommandBuffer(s.Key.item2, s.Value);
                cbs.Remove(s.Key);
            }

            if (cbs.Count == 0)
            {
                m_CameraCommandBuffers.Remove(camera);
            }
        }
        internal void RemoveCommandBuffer(PostProcessingBase effect, CameraEvent cameraEvent, CommandBuffer cb)
        {
            camera.RemoveCommandBuffer(cameraEvent, cb);
            var cbs = GetCommandBuffers(camera);

            if (cbs == null)
            {
                Debug.LogWarningFormat("Camera '{0}' was not registered while trying to remove CommandBuffer for ({1}, {2})", camera, effect.GetType().Name, cameraEvent);
                return;
            }
            var key = new Tuple <Type, CameraEvent>(effect.GetType(), cameraEvent);

            if (!cbs.ContainsKey(key))
            {
                Debug.LogWarningFormat("CommandBuffer for ({1}, {2}) was not registered while trying to remove CommandBuffer from Camera '{0}'", camera, effect.GetType().Name, cameraEvent);
                return;
            }

            cbs.Remove(key);
            if (cbs.Count == 0)
            {
                m_CameraCommandBuffers.Remove(camera);
            }
        }