using System;
using System.Collections.Generic;
namespace UnityEngine.Rendering
{
///
/// Templated class for
///
///
public abstract class DebugDisplaySettings : IDebugDisplaySettings
where T : IDebugDisplaySettings, new()
{
///
/// The set of containing the settings for this debug display
///
protected readonly HashSet m_Settings = new HashSet();
private static readonly Lazy s_Instance = new Lazy(() =>
{
var instance = new T();
instance.Reset();
return instance;
});
///
/// The singleton instance that contains the current settings of Rendering Debugger.
///
public static T Instance => s_Instance.Value;
#region IDebugDisplaySettingsQuery
///
/// Returns true if any of the debug settings are currently active.
///
public virtual bool AreAnySettingsActive
{
get
{
foreach (IDebugDisplaySettingsData setting in m_Settings)
{
if (setting.AreAnySettingsActive)
return true;
}
return false;
}
}
///
/// Checks whether the current state of these settings allows post-processing.
///
public virtual bool IsPostProcessingAllowed
{
get
{
// Only enable post-processing if we aren't using certain debug-views.
bool postProcessingAllowed = true;
foreach (IDebugDisplaySettingsData setting in m_Settings)
postProcessingAllowed &= setting.IsPostProcessingAllowed;
return postProcessingAllowed;
}
}
///
/// Returns true if lighting is active for current state of debug settings.
///
public virtual bool IsLightingActive
{
get
{
bool lightingActive = true;
foreach (IDebugDisplaySettingsData setting in m_Settings)
lightingActive &= setting.IsLightingActive;
return lightingActive;
}
}
#endregion
///
/// Adds a new to this settings
///
/// The type of to be added
/// The to be added
/// The type of that has been added
protected TData Add(TData newData) where TData : IDebugDisplaySettingsData
{
m_Settings.Add(newData);
return newData;
}
///
/// Executes an action for each element
///
///
public void ForEach(Action onExecute)
{
foreach (IDebugDisplaySettingsData setting in m_Settings)
{
onExecute(setting);
}
}
///
/// Reset the stored debug settings
///
public virtual void Reset()
{
m_Settings.Clear();
}
///
/// Attempts to get the color that should be used to clear the screen according to current debug settings.
///
/// A reference to the screen clear color to use.
/// True if the color reference was updated, and false otherwise.
public virtual bool TryGetScreenClearColor(ref Color color)
{
foreach (IDebugDisplaySettingsData setting in m_Settings)
{
if (setting.TryGetScreenClearColor(ref color))
return true;
}
return false;
}
}
}