DebugDisplaySettings.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace UnityEngine.Rendering.Universal
  5. {
  6. public class DebugDisplaySettings : IDebugDisplaySettingsQuery
  7. {
  8. private readonly HashSet<IDebugDisplaySettingsData> m_Settings = new HashSet<IDebugDisplaySettingsData>();
  9. private static readonly Lazy<DebugDisplaySettings> s_Instance = new Lazy<DebugDisplaySettings>(() => new DebugDisplaySettings());
  10. /// <summary>
  11. /// The singleton instance that contains the current settings of URP Rendering Debugger.
  12. /// </summary>
  13. public static DebugDisplaySettings Instance => s_Instance.Value;
  14. DebugDisplaySettingsCommon CommonSettings { get; set; }
  15. /// <summary>
  16. /// Material-related Rendering Debugger settings.
  17. /// </summary>
  18. internal DebugDisplaySettingsMaterial MaterialSettings { get; private set; }
  19. /// <summary>
  20. /// Rendering-related Rendering Debugger settings.
  21. /// </summary>
  22. internal DebugDisplaySettingsRendering RenderingSettings { get; private set; }
  23. /// <summary>
  24. /// Lighting-related Rendering Debugger settings.
  25. /// </summary>
  26. internal DebugDisplaySettingsLighting LightingSettings { get; private set; }
  27. #region IDebugDisplaySettingsQuery
  28. /// <summary>
  29. /// Returns true if any of the debug settings are currently active.
  30. /// </summary>
  31. public bool AreAnySettingsActive => MaterialSettings.AreAnySettingsActive ||
  32. LightingSettings.AreAnySettingsActive ||
  33. RenderingSettings.AreAnySettingsActive;
  34. public bool TryGetScreenClearColor(ref Color color)
  35. {
  36. return MaterialSettings.TryGetScreenClearColor(ref color) ||
  37. RenderingSettings.TryGetScreenClearColor(ref color) ||
  38. LightingSettings.TryGetScreenClearColor(ref color);
  39. }
  40. /// <summary>
  41. /// Returns true if lighting is active for current state of debug settings.
  42. /// </summary>
  43. public bool IsLightingActive => MaterialSettings.IsLightingActive &&
  44. RenderingSettings.IsLightingActive &&
  45. LightingSettings.IsLightingActive;
  46. /// <summary>
  47. /// Returns true if the current state of debug settings allows post-processing.
  48. /// </summary>
  49. public bool IsPostProcessingAllowed
  50. {
  51. get
  52. {
  53. DebugPostProcessingMode debugPostProcessingMode = RenderingSettings.debugPostProcessingMode;
  54. switch (debugPostProcessingMode)
  55. {
  56. case DebugPostProcessingMode.Disabled:
  57. {
  58. return false;
  59. }
  60. case DebugPostProcessingMode.Auto:
  61. {
  62. // Only enable post-processing if we aren't using certain debug-views...
  63. return MaterialSettings.IsPostProcessingAllowed &&
  64. RenderingSettings.IsPostProcessingAllowed &&
  65. LightingSettings.IsPostProcessingAllowed;
  66. }
  67. case DebugPostProcessingMode.Enabled:
  68. {
  69. return true;
  70. }
  71. default:
  72. {
  73. throw new ArgumentOutOfRangeException(nameof(debugPostProcessingMode), $"Invalid post-processing state {debugPostProcessingMode}");
  74. }
  75. }
  76. }
  77. }
  78. #endregion
  79. private TData Add<TData>(TData newData) where TData : IDebugDisplaySettingsData
  80. {
  81. m_Settings.Add(newData);
  82. return newData;
  83. }
  84. DebugDisplaySettings()
  85. {
  86. Reset();
  87. }
  88. internal void Reset()
  89. {
  90. m_Settings.Clear();
  91. CommonSettings = Add(new DebugDisplaySettingsCommon());
  92. MaterialSettings = Add(new DebugDisplaySettingsMaterial());
  93. LightingSettings = Add(new DebugDisplaySettingsLighting());
  94. RenderingSettings = Add(new DebugDisplaySettingsRendering());
  95. }
  96. internal void ForEach(Action<IDebugDisplaySettingsData> onExecute)
  97. {
  98. foreach (IDebugDisplaySettingsData setting in m_Settings)
  99. {
  100. onExecute(setting);
  101. }
  102. }
  103. }
  104. }