public override void OnInspectorGUI()
        {
            BeautifySettings.ManageBuildOptimizationStatus();

            serializedObject.Update();

            SetStyles();

            Beautify.TonemapOperator prevTonemap = beautify.tonemap.value;
            bool prevDirectWrite = beautify.directWrite.value;

            EditorGUILayout.BeginVertical();
            {
                GUI.skin.label.alignment = TextAnchor.MiddleCenter;
                GUILayout.BeginHorizontal(blackBack);
                GUILayout.Label(headerTex, GUILayout.ExpandWidth(true));
                GUI.skin.label.alignment = TextAnchor.MiddleLeft;
                GUILayout.EndHorizontal();

                Camera cam = Camera.main;
                if (cam != null)
                {
                    UniversalAdditionalCameraData data = cam.GetComponent <UniversalAdditionalCameraData>();
                    if (data != null && !data.renderPostProcessing)
                    {
                        EditorGUILayout.HelpBox("Post Processing option is disabled in the camera.", MessageType.Warning);
                        if (GUILayout.Button("Go to Camera"))
                        {
                            Selection.activeObject = cam;
                        }
                        EditorGUILayout.Separator();
                    }
                }

                UnityEngine.Rendering.Universal.UniversalRenderPipelineAsset pipe = UnityEngine.Rendering.GraphicsSettings.currentRenderPipeline as UnityEngine.Rendering.Universal.UniversalRenderPipelineAsset;
                if (pipe == null)
                {
                    EditorGUILayout.HelpBox("Universal Rendering Pipeline asset is not set in 'Project Settings / Graphics' !", MessageType.Error);
                    EditorGUILayout.Separator();
                    GUI.enabled = false;
                }
                else if (!BeautifyRendererFeature.installed)
                {
                    EditorGUILayout.HelpBox("Beautify Render Feature must be added to the rendering pipeline renderer.", MessageType.Error);
                    if (GUILayout.Button("Go to Universal Rendering Pipeline Asset"))
                    {
                        Selection.activeObject = pipe;
                    }
                    EditorGUILayout.Separator();
                    GUI.enabled = false;
                }
                else if (beautify.RequiresDepthTexture())
                {
                    if (!pipe.supportsCameraDepthTexture)
                    {
                        EditorGUILayout.HelpBox("Depth Texture option may be required for certain effects. Check Universal Rendering Pipeline asset!", MessageType.Warning);
                        if (GUILayout.Button("Go to Universal Rendering Pipeline Asset"))
                        {
                            Selection.activeObject = pipe;
                        }
                        EditorGUILayout.Separator();
                    }
                }

                bool usesHDREffect = beautify.tonemap.value != Beautify.TonemapOperator.Linear;
                if (usesHDREffect && (QualitySettings.activeColorSpace != ColorSpace.Linear || (Camera.main != null && !Camera.main.allowHDR)))
                {
                    EditorGUILayout.HelpBox("Some effects, like bloom or tonemapping, works better with Linear Color Space and HDR enabled. Enable Linear color space in Player Settings and check your camera and pipeline HDR setting.", MessageType.Warning);
                }

                // sections
                foreach (var section in sections)
                {
                    bool printSectionHeader = true;

                    // individual properties
                    foreach (var field in section.Value.singleFields)
                    {
                        var parameter   = Unpack(propertyFetcher.Find(field.Name));
                        var displayName = parameter.displayName;
                        if (field.GetCustomAttribute(typeof(Beautify.DisplayName)) is Beautify.DisplayName displayNameAttrib)
                        {
                            displayName = displayNameAttrib.name;
                        }
                        bool indent;
                        if (!IsVisible(parameter, field, out indent))
                        {
                            continue;
                        }

                        if (printSectionHeader)
                        {
                            GUILayout.Space(6.0f);
                            Rect rect = GUILayoutUtility.GetRect(16f, 22f, sectionGroupStyle);
                            GUI.Box(rect, ObjectNames.NicifyVariableName(section.Key.GetType().Name), sectionGroupStyle);
                            printSectionHeader = false;
                        }

                        DrawPropertyField(parameter, field, indent);

                        if (beautify.disabled.value)
                        {
                            GUI.enabled = false;
                        }
                    }
                    GUILayout.Space(6.0f);

                    // grouped properties
                    foreach (var group in section.Value.groups)
                    {
                        Beautify.SettingsGroup settingsGroup = group.Key;
                        string groupName         = ObjectNames.NicifyVariableName(settingsGroup.GetType().Name);
                        bool   printGroupFoldout = true;
                        bool   firstField        = true;
                        bool   groupHasContent   = false;

                        foreach (var field in group.Value)
                        {
                            var  parameter = Unpack(propertyFetcher.Find(field.Name));
                            bool indent;
                            if (!IsVisible(parameter, field, out indent))
                            {
                                if (firstField)
                                {
                                    break;
                                }
                                continue;
                            }

                            firstField = false;
                            if (printSectionHeader)
                            {
                                GUILayout.Space(6.0f);
                                Rect rect = GUILayoutUtility.GetRect(16f, 22f, sectionGroupStyle);
                                GUI.Box(rect, ObjectNames.NicifyVariableName(section.Key.GetType().Name), sectionGroupStyle);
                                printSectionHeader = false;
                            }

                            if (printGroupFoldout)
                            {
                                printGroupFoldout        = false;
                                settingsGroup.IsExpanded = EditorGUILayout.Foldout(settingsGroup.IsExpanded, groupName, true, foldoutStyle);
                                if (!settingsGroup.IsExpanded)
                                {
                                    break;
                                }
                            }

                            DrawPropertyField(parameter, field, indent);
                            groupHasContent = true;

                            if (parameter.value.propertyType == SerializedPropertyType.Boolean)
                            {
                                if (!parameter.value.boolValue)
                                {
                                    var hasToggleSectionBegin = field.GetCustomAttributes(typeof(Beautify.ToggleAllFields)).Any();
                                    if (hasToggleSectionBegin)
                                    {
                                        break;
                                    }
                                }
                            }
                            else if (field.Name.Equals("depthOfFieldFocusMode"))
                            {
                                SerializedProperty prop = serializedObject.FindProperty(field.Name);
                                if (prop != null)
                                {
                                    var value = prop.FindPropertyRelative("m_Value");
                                    if (value != null && value.enumValueIndex == (int)Beautify.DoFFocusMode.FollowTarget)
                                    {
                                        EditorGUILayout.HelpBox("Assign target in the Beautify Settings component.", MessageType.Info);
                                    }
                                }
                            }
                        }
                        if (groupHasContent)
                        {
                            GUILayout.Space(6.0f);
                        }
                    }
                }
            }
            EditorGUILayout.EndVertical();

            serializedObject.ApplyModifiedProperties();

            if (prevTonemap != beautify.tonemap.value && beautify.tonemap.value == Beautify.TonemapOperator.ACES)
            {
                beautify.saturate.value         = 0;
                beautify.saturate.overrideState = true;
                beautify.contrast.value         = 1f;
                beautify.contrast.overrideState = true;
            }

            if (beautify.directWrite.value != prevDirectWrite)
            {
                EditorApplication.delayCall += () =>
                                               UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
            }
        }
Exemplo n.º 2
0
 void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
 {
     _instance       = null;
     _beautifyVolume = null;
     _beautify       = null;
 }
        void DrawPropertyField(SerializedDataParameter property, MemberInfo field, bool indent)
        {
            if (indent)
            {
                EditorGUI.indentLevel++;
            }

            var displayName = property.displayName;

            if (field.GetCustomAttribute(typeof(Beautify.DisplayName)) is Beautify.DisplayName displayNameAttrib)
            {
                displayName = displayNameAttrib.name;
            }

            if (property.value.propertyType == SerializedPropertyType.Boolean)
            {
                if (field.GetCustomAttribute(typeof(Beautify.GlobalOverride)) != null)
                {
                    BoolParameter pr   = property.GetObjectRef <BoolParameter>();
                    bool          prev = pr.value;

                    using (new EditorGUILayout.HorizontalScope()) {
                        var overrideRect = GUILayoutUtility.GetRect(17f, 17f, GUILayout.ExpandWidth(false));
                        overrideRect.yMin += 4f;
                        bool value = GUI.Toggle(overrideRect, prev, GUIContent.none);

                        string tooltip = null;
                        if (field.GetCustomAttribute(typeof(TooltipAttribute)) is TooltipAttribute tooltipAttribute)
                        {
                            tooltip = tooltipAttribute.tooltip;
                        }

                        using (new EditorGUI.DisabledScope(!prev)) {
                            EditorGUILayout.LabelField(new GUIContent(displayName, tooltip));
                        }

                        if (value != prev)
                        {
                            pr.value = value;
                            SerializedProperty prop = serializedObject.FindProperty(field.Name);
                            if (prop != null)
                            {
                                var boolProp = prop.FindPropertyRelative("m_Value");
                                if (boolProp != null)
                                {
                                    boolProp.boolValue = value;
                                }
                                if (value)
                                {
                                    var overrideProp = prop.FindPropertyRelative("m_OverrideState");
                                    if (overrideProp != null)
                                    {
                                        overrideProp.boolValue = true;
                                    }
                                }
                            }
                            if (field.GetCustomAttribute(typeof(Beautify.BuildToggle)) != null)
                            {
                                BeautifySettings.SetStripShaderKeywords(beautify);
                            }
                        }
                    }
                }
                else
                {
                    PropertyField(property, new GUIContent(displayName));
                }
            }
            else
            {
                PropertyField(property, new GUIContent(displayName));
            }

            if (indent)
            {
                EditorGUI.indentLevel--;
            }
        }