PostProcessDebugEditor.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using UnityEngine;
  2. using UnityEngine.Rendering.PostProcessing;
  3. namespace UnityEditor.Rendering.PostProcessing
  4. {
  5. [CustomEditor(typeof(PostProcessDebug))]
  6. sealed class PostProcessDebugEditor : BaseEditor<PostProcessDebug>
  7. {
  8. SerializedProperty m_PostProcessLayer;
  9. SerializedProperty m_LightMeterEnabled;
  10. SerializedProperty m_HistogramEnabled;
  11. SerializedProperty m_WaveformEnabled;
  12. SerializedProperty m_VectorscopeEnabled;
  13. SerializedProperty m_Overlay;
  14. SerializedObject m_LayerObject;
  15. SerializedProperty m_LightMeterShowCurves;
  16. SerializedProperty m_HistogramChannel;
  17. SerializedProperty m_WaveformExposure;
  18. SerializedProperty m_VectorscopeExposure;
  19. SerializedProperty m_LinearDepth;
  20. SerializedProperty m_MotionColorIntensity;
  21. SerializedProperty m_MotionGridSize;
  22. SerializedProperty m_ColorBlindness;
  23. SerializedProperty m_ColorBlindnessStrength;
  24. void OnEnable()
  25. {
  26. m_PostProcessLayer = FindProperty(x => x.postProcessLayer);
  27. m_LightMeterEnabled = FindProperty(x => x.lightMeter);
  28. m_HistogramEnabled = FindProperty(x => x.histogram);
  29. m_WaveformEnabled = FindProperty(x => x.waveform);
  30. m_VectorscopeEnabled = FindProperty(x => x.vectorscope);
  31. m_Overlay = FindProperty(x => x.debugOverlay);
  32. if (m_PostProcessLayer.objectReferenceValue != null)
  33. RebuildProperties();
  34. }
  35. void RebuildProperties()
  36. {
  37. if (m_PostProcessLayer.objectReferenceValue == null)
  38. return;
  39. m_LayerObject = new SerializedObject(m_Target.postProcessLayer);
  40. m_LightMeterShowCurves = m_LayerObject.FindProperty("debugLayer.lightMeter.showCurves");
  41. m_HistogramChannel = m_LayerObject.FindProperty("debugLayer.histogram.channel");
  42. m_WaveformExposure = m_LayerObject.FindProperty("debugLayer.waveform.exposure");
  43. m_VectorscopeExposure = m_LayerObject.FindProperty("debugLayer.vectorscope.exposure");
  44. m_LinearDepth = m_LayerObject.FindProperty("debugLayer.overlaySettings.linearDepth");
  45. m_MotionColorIntensity = m_LayerObject.FindProperty("debugLayer.overlaySettings.motionColorIntensity");
  46. m_MotionGridSize = m_LayerObject.FindProperty("debugLayer.overlaySettings.motionGridSize");
  47. m_ColorBlindness = m_LayerObject.FindProperty("debugLayer.overlaySettings.colorBlindnessType");
  48. m_ColorBlindnessStrength = m_LayerObject.FindProperty("debugLayer.overlaySettings.colorBlindnessStrength");
  49. }
  50. public override void OnInspectorGUI()
  51. {
  52. serializedObject.Update();
  53. using (var changed = new EditorGUI.ChangeCheckScope())
  54. {
  55. EditorGUILayout.PropertyField(m_PostProcessLayer);
  56. serializedObject.ApplyModifiedProperties(); // Needed to rebuild properties after a change
  57. serializedObject.Update();
  58. if (changed.changed)
  59. RebuildProperties();
  60. }
  61. if (m_PostProcessLayer.objectReferenceValue != null)
  62. {
  63. m_LayerObject.Update();
  64. // Overlays
  65. EditorGUILayout.Space();
  66. EditorGUILayout.LabelField(EditorUtilities.GetContent("Overlay"), EditorStyles.boldLabel);
  67. EditorGUI.indentLevel++;
  68. EditorGUILayout.PropertyField(m_Overlay);
  69. DoOverlayGUI(DebugOverlay.Depth, m_LinearDepth);
  70. DoOverlayGUI(DebugOverlay.MotionVectors, m_MotionColorIntensity, m_MotionGridSize);
  71. DoOverlayGUI(DebugOverlay.ColorBlindnessSimulation, m_ColorBlindness, m_ColorBlindnessStrength);
  72. // Special cases
  73. if (m_Overlay.intValue == (int)DebugOverlay.NANTracker && m_Target.postProcessLayer.stopNaNPropagation)
  74. EditorGUILayout.HelpBox("Disable \"Stop NaN Propagation\" in the Post-process layer or NaNs will be overwritten!", MessageType.Warning);
  75. EditorGUI.indentLevel--;
  76. // Monitors
  77. EditorGUILayout.Space();
  78. EditorGUILayout.LabelField(EditorUtilities.GetContent("Monitors"), EditorStyles.boldLabel);
  79. EditorGUI.indentLevel++;
  80. DoMonitorGUI(EditorUtilities.GetContent("Light Meter"), m_LightMeterEnabled, m_LightMeterShowCurves);
  81. DoMonitorGUI(EditorUtilities.GetContent("Histogram"), m_HistogramEnabled, m_HistogramChannel);
  82. DoMonitorGUI(EditorUtilities.GetContent("Waveform"), m_WaveformEnabled, m_WaveformExposure);
  83. DoMonitorGUI(EditorUtilities.GetContent("Vectoscope"), m_VectorscopeEnabled, m_VectorscopeExposure);
  84. EditorGUI.indentLevel--;
  85. m_LayerObject.ApplyModifiedProperties();
  86. }
  87. serializedObject.ApplyModifiedProperties();
  88. }
  89. void DoMonitorGUI(GUIContent content, SerializedProperty prop, params SerializedProperty[] settings)
  90. {
  91. EditorGUILayout.PropertyField(prop, content);
  92. if (settings == null || settings.Length == 0)
  93. return;
  94. if (prop.boolValue)
  95. {
  96. EditorGUI.indentLevel++;
  97. foreach (var p in settings)
  98. EditorGUILayout.PropertyField(p);
  99. EditorGUI.indentLevel--;
  100. }
  101. }
  102. void DoOverlayGUI(DebugOverlay overlay, params SerializedProperty[] settings)
  103. {
  104. if (m_Overlay.intValue != (int)overlay)
  105. return;
  106. if (settings == null || settings.Length == 0)
  107. return;
  108. foreach (var p in settings)
  109. EditorGUILayout.PropertyField(p);
  110. }
  111. }
  112. }