You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
4.8 KiB

  1. using UnityEngine.PostProcessing;
  2. namespace UnityEditor.PostProcessing
  3. {
  4. using Mode = BuiltinDebugViewsModel.Mode;
  5. using Settings = BuiltinDebugViewsModel.Settings;
  6. [PostProcessingModelEditor(typeof(BuiltinDebugViewsModel), alwaysEnabled: true)]
  7. public class BuiltinDebugViewsEditor : PostProcessingModelEditor
  8. {
  9. struct DepthSettings
  10. {
  11. public SerializedProperty scale;
  12. }
  13. struct MotionVectorsSettings
  14. {
  15. public SerializedProperty sourceOpacity;
  16. public SerializedProperty motionImageOpacity;
  17. public SerializedProperty motionImageAmplitude;
  18. public SerializedProperty motionVectorsOpacity;
  19. public SerializedProperty motionVectorsResolution;
  20. public SerializedProperty motionVectorsAmplitude;
  21. }
  22. SerializedProperty m_Mode;
  23. DepthSettings m_Depth;
  24. MotionVectorsSettings m_MotionVectors;
  25. public override void OnEnable()
  26. {
  27. m_Mode = FindSetting((Settings x) => x.mode);
  28. m_Depth = new DepthSettings
  29. {
  30. scale = FindSetting((Settings x) => x.depth.scale)
  31. };
  32. m_MotionVectors = new MotionVectorsSettings
  33. {
  34. sourceOpacity = FindSetting((Settings x) => x.motionVectors.sourceOpacity),
  35. motionImageOpacity = FindSetting((Settings x) => x.motionVectors.motionImageOpacity),
  36. motionImageAmplitude = FindSetting((Settings x) => x.motionVectors.motionImageAmplitude),
  37. motionVectorsOpacity = FindSetting((Settings x) => x.motionVectors.motionVectorsOpacity),
  38. motionVectorsResolution = FindSetting((Settings x) => x.motionVectors.motionVectorsResolution),
  39. motionVectorsAmplitude = FindSetting((Settings x) => x.motionVectors.motionVectorsAmplitude),
  40. };
  41. }
  42. public override void OnInspectorGUI()
  43. {
  44. EditorGUILayout.PropertyField(m_Mode);
  45. int mode = m_Mode.intValue;
  46. if (mode == (int)Mode.Depth)
  47. {
  48. EditorGUILayout.PropertyField(m_Depth.scale);
  49. }
  50. else if (mode == (int)Mode.MotionVectors)
  51. {
  52. EditorGUILayout.HelpBox("Switch to play mode to see motion vectors.", MessageType.Info);
  53. EditorGUILayout.LabelField("Source Image", EditorStyles.boldLabel);
  54. EditorGUI.indentLevel++;
  55. EditorGUILayout.PropertyField(m_MotionVectors.sourceOpacity, EditorGUIHelper.GetContent("Opacity"));
  56. EditorGUI.indentLevel--;
  57. EditorGUILayout.Space();
  58. EditorGUILayout.LabelField("Motion Vectors (overlay)", EditorStyles.boldLabel);
  59. EditorGUI.indentLevel++;
  60. if (m_MotionVectors.motionImageOpacity.floatValue > 0f)
  61. EditorGUILayout.HelpBox("Please keep opacity to 0 if you're subject to motion sickness.", MessageType.Warning);
  62. EditorGUILayout.PropertyField(m_MotionVectors.motionImageOpacity, EditorGUIHelper.GetContent("Opacity"));
  63. EditorGUILayout.PropertyField(m_MotionVectors.motionImageAmplitude, EditorGUIHelper.GetContent("Amplitude"));
  64. EditorGUI.indentLevel--;
  65. EditorGUILayout.Space();
  66. EditorGUILayout.LabelField("Motion Vectors (arrows)", EditorStyles.boldLabel);
  67. EditorGUI.indentLevel++;
  68. EditorGUILayout.PropertyField(m_MotionVectors.motionVectorsOpacity, EditorGUIHelper.GetContent("Opacity"));
  69. EditorGUILayout.PropertyField(m_MotionVectors.motionVectorsResolution, EditorGUIHelper.GetContent("Resolution"));
  70. EditorGUILayout.PropertyField(m_MotionVectors.motionVectorsAmplitude, EditorGUIHelper.GetContent("Amplitude"));
  71. EditorGUI.indentLevel--;
  72. }
  73. else
  74. {
  75. CheckActiveEffect(mode == (int)Mode.AmbientOcclusion && !profile.ambientOcclusion.enabled, "Ambient Occlusion");
  76. CheckActiveEffect(mode == (int)Mode.FocusPlane && !profile.depthOfField.enabled, "Depth Of Field");
  77. CheckActiveEffect(mode == (int)Mode.EyeAdaptation && !profile.eyeAdaptation.enabled, "Eye Adaptation");
  78. CheckActiveEffect((mode == (int)Mode.LogLut || mode == (int)Mode.PreGradingLog) && !profile.colorGrading.enabled, "Color Grading");
  79. CheckActiveEffect(mode == (int)Mode.UserLut && !profile.userLut.enabled, "User Lut");
  80. }
  81. }
  82. void CheckActiveEffect(bool expr, string name)
  83. {
  84. if (expr)
  85. EditorGUILayout.HelpBox(string.Format("{0} isn't enabled, the debug view won't work.", name), MessageType.Warning);
  86. }
  87. }
  88. }