using System;
using System.Collections.Generic;
namespace UnityEngine.Rendering
{
///
/// Templated class for
///
/// The specific type of Debug Display Settings that is inheriting from the IDebugDisplaySettings interface.
public abstract class DebugDisplaySettings : IDebugDisplaySettings
where T : IDebugDisplaySettings, new()
{
class IDebugDisplaySettingsDataComparer : IEqualityComparer
{
public bool Equals(IDebugDisplaySettingsData x, IDebugDisplaySettingsData y)
{
if (ReferenceEquals(x, y))
return true;
if (x == null || y == null)
return false;
return x.GetType() == y.GetType();
}
public int GetHashCode(IDebugDisplaySettingsData obj)
{
// Define your custom hashing logic based on the properties you want to include.
unchecked
{
int hash = 17;
hash = hash * 23 + obj.GetType().GetHashCode();
return hash;
}
}
}
///
/// The set of containing the settings for this debug display
///
protected readonly HashSet m_Settings = new HashSet(new IDebugDisplaySettingsDataComparer());
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;
}
///
IDebugDisplaySettingsData IDebugDisplaySettings.Add(IDebugDisplaySettingsData newData)
{
m_Settings.Add(newData);
return newData;
}
///
/// Executes an action for each element
///
/// The action to be executed on each element in the Debug Display Settings data.
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;
}
}
}