public void OnGUI()
        {
            if (m_Asset.isDirty)
            {
                RefreshEditors();
                m_Asset.isDirty = false;
            }

            EditorGUILayout.LabelField(EditorUtilities.GetContent("Overrides"), EditorStyles.boldLabel);

            // Override list
            for (int i = 0; i < m_Editors.Count; i++)
            {
                var    editor = m_Editors[i];
                string title  = editor.GetDisplayTitle();
                int    id     = i; // Needed for closure capture below

                EditorUtilities.DrawSplitter();
                bool displayContent = EditorUtilities.DrawHeader(
                    title,
                    editor.baseProperty,
                    editor.activeProperty,
                    editor.target,
                    () => ResetEffectOverride(editor.target.GetType(), id),
                    () => RemoveEffectOverride(id)
                    );

                if (displayContent)
                {
                    using (new EditorGUI.DisabledScope(!editor.activeProperty.boolValue))
                        editor.OnInternalInspectorGUI();
                }
            }

            if (m_Editors.Count > 0)
            {
                EditorUtilities.DrawSplitter();
                EditorGUILayout.Space();
            }
            else
            {
                EditorGUILayout.HelpBox("No override set on this volume.", MessageType.Info);
            }

            if (GUILayout.Button("Add effect...", EditorStyles.miniButton))
            {
                var menu = new GenericMenu();

                var typeMap = PostProcessManager.instance.settingsTypes;
                foreach (var kvp in typeMap)
                {
                    var  type   = kvp.Key;
                    var  title  = EditorUtilities.GetContent(kvp.Value.menuItem);
                    bool exists = m_Asset.HasSettings(type);

                    if (!exists)
                    {
                        menu.AddItem(title, false, () => AddEffectOverride(type));
                    }
                    else
                    {
                        menu.AddDisabledItem(title);
                    }
                }

                menu.ShowAsContext();
            }

            EditorGUILayout.Space();
        }
Beispiel #2
0
        protected void PropertyField(SerializedParameterOverride property)
        {
            var title = EditorUtilities.GetContent(property.displayName);

            PropertyField(property, title);
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.PropertyField(m_IsGlobal);

            if (!m_IsGlobal.boolValue) // Blend radius is not needed for global volumes
            {
                EditorGUILayout.PropertyField(m_BlendRadius);
            }

            EditorGUILayout.PropertyField(m_Weight);
            EditorGUILayout.PropertyField(m_Priority);

            bool assetHasChanged = false;
            bool showCopy        = m_Profile.objectReferenceValue != null;

            // The layout system sort of break alignement when mixing inspector fields with custom
            // layouted fields, do the layout manually instead
            int   buttonWidth    = showCopy ? 45 : 60;
            float indentOffset   = EditorGUI.indentLevel * 15f;
            var   lineRect       = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight);
            var   labelRect      = new Rect(lineRect.x, lineRect.y, EditorGUIUtility.labelWidth - indentOffset, lineRect.height);
            var   fieldRect      = new Rect(labelRect.xMax, lineRect.y, lineRect.width - labelRect.width - buttonWidth * (showCopy ? 2 : 1), lineRect.height);
            var   buttonNewRect  = new Rect(fieldRect.xMax, lineRect.y, buttonWidth, lineRect.height);
            var   buttonCopyRect = new Rect(buttonNewRect.xMax, lineRect.y, buttonWidth, lineRect.height);

            EditorGUI.PrefixLabel(labelRect, EditorUtilities.GetContent("Profile|A reference to a profile asset."));

            using (var scope = new EditorGUI.ChangeCheckScope())
            {
                m_Profile.objectReferenceValue = (PostProcessProfile)EditorGUI.ObjectField(fieldRect, m_Profile.objectReferenceValue, typeof(PostProcessProfile), false);
                assetHasChanged = scope.changed;
            }

            if (GUI.Button(buttonNewRect, EditorUtilities.GetContent("New|Create a new profile."), showCopy ? EditorStyles.miniButtonLeft : EditorStyles.miniButton))
            {
                // By default, try to put assets in a folder next to the currently active
                // scene file. If the user isn't a scene, put them in root instead.
                var targetName = m_Target.name;
                var scene      = m_Target.gameObject.scene;
                var path       = string.Empty;

                if (string.IsNullOrEmpty(scene.path))
                {
                    path = "Assets/";
                }
                else
                {
                    var scenePath   = Path.GetDirectoryName(scene.path);
                    var extPath     = scene.name + "_Profiles";
                    var profilePath = scenePath + "/" + extPath;

                    if (!AssetDatabase.IsValidFolder(profilePath))
                    {
                        AssetDatabase.CreateFolder(scenePath, extPath);
                    }

                    path = profilePath + "/";
                }

                path += targetName + " Profile.asset";
                path  = AssetDatabase.GenerateUniqueAssetPath(path);

                var asset = CreateInstance <PostProcessProfile>();
                AssetDatabase.CreateAsset(asset, path);
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();

                m_Profile.objectReferenceValue = asset;
                assetHasChanged = true;
            }

            if (showCopy && GUI.Button(buttonCopyRect, EditorUtilities.GetContent("Clone|Create a new profile and copy the content of the currently assigned profile."), EditorStyles.miniButtonRight))
            {
                // Duplicate the currently assigned profile and save it as a new profile
                var origin = (PostProcessProfile)m_Profile.objectReferenceValue;
                var path   = AssetDatabase.GetAssetPath(origin);
                path = AssetDatabase.GenerateUniqueAssetPath(path);

                var asset = Instantiate(origin);
                asset.settings.Clear();
                AssetDatabase.CreateAsset(asset, path);

                foreach (var item in origin.settings)
                {
                    var itemCopy = Instantiate(item);
                    itemCopy.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy;
                    itemCopy.name      = item.name;
                    asset.settings.Add(itemCopy);
                    AssetDatabase.AddObjectToAsset(itemCopy, asset);
                }

                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();

                m_Profile.objectReferenceValue = asset;
                assetHasChanged = true;
            }

            EditorGUILayout.Space();

            if (m_Profile.objectReferenceValue == null)
            {
                if (assetHasChanged)
                {
                    m_EffectList.Clear(); // Asset wasn't null before, do some cleanup
                }
                EditorGUILayout.HelpBox("Assign a Post-process Profile to this volume using the \"Asset\" field or create one automatically by clicking the \"New\" button.\nAssets are automatically put in a folder next to your scene file. If you scene hasn't been saved yet they will be created at the root of the Assets folder.", MessageType.Info);
            }
            else
            {
                if (assetHasChanged)
                {
                    RefreshEffectListEditor((PostProcessProfile)m_Profile.objectReferenceValue);
                }

                m_EffectList.OnGUI();
            }

            serializedObject.ApplyModifiedProperties();
        }
Beispiel #4
0
        protected void PropertyField(SerializedParameterOverride property, GUIContent title)
        {
            // Check for DisplayNameAttribute first
            var displayNameAttr = property.GetAttribute <DisplayNameAttribute>();

            if (displayNameAttr != null)
            {
                title.text = displayNameAttr.displayName;
            }

            // Add tooltip if it's missing and an attribute is available
            if (string.IsNullOrEmpty(title.tooltip))
            {
                var tooltipAttr = property.GetAttribute <TooltipAttribute>();
                if (tooltipAttr != null)
                {
                    title.tooltip = tooltipAttr.tooltip;
                }
            }

            // Look for a compatible attribute decorator and break as soon as we find one
            AttributeDecorator decorator = null;
            Attribute          attribute = null;

            foreach (var attr in property.attributes)
            {
                decorator = EditorUtilities.GetDecorator(attr.GetType());
                attribute = attr;

                if (decorator != null)
                {
                    break;
                }
            }

            bool invalidProp = false;

            if (decorator != null && !decorator.IsAutoProperty())
            {
                if (decorator.OnGUI(property.value, property.overrideState, title, attribute))
                {
                    return;
                }

                // Attribute is invalid for the specified property; use default unity field instead
                invalidProp = true;
            }

            using (new EditorGUILayout.HorizontalScope())
            {
                // Override checkbox
                var overrideRect = GUILayoutUtility.GetRect(17f, 17f, GUILayout.ExpandWidth(false));
                overrideRect.yMin += 4f;
                EditorUtilities.DrawOverrideCheckbox(overrideRect, property.overrideState);

                // Property
                using (new EditorGUI.DisabledScope(!property.overrideState.boolValue))
                {
                    if (decorator != null && !invalidProp)
                    {
                        if (decorator.OnGUI(property.value, property.overrideState, title, attribute))
                        {
                            return;
                        }
                    }

                    // Default unity field
                    EditorGUILayout.PropertyField(property.value, title);
                }
            }
        }
Beispiel #5
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.LabelField(EditorUtilities.GetContent("Volume blending"), EditorStyles.boldLabel);
            EditorGUI.indentLevel++;
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.PrefixLabel("Trigger");
                    EditorGUI.indentLevel--; // The editor adds an indentation after the prefix label, this removes it

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        m_VolumeTrigger.objectReferenceValue = (Transform)EditorGUILayout.ObjectField(m_VolumeTrigger.objectReferenceValue, typeof(Transform), false);
                        if (GUILayout.Button(EditorUtilities.GetContent("This|Assigns the current GameObject as a trigger."), EditorStyles.miniButton))
                        {
                            m_VolumeTrigger.objectReferenceValue = m_Target.transform;
                        }
                    }

                    EditorGUI.indentLevel++;
                }

                EditorGUILayout.PropertyField(m_VolumeLayer, EditorUtilities.GetContent("Layer"));

                int mask = m_VolumeLayer.intValue;
                if (mask == 0)
                {
                    EditorGUILayout.HelpBox("No layer has been set, the trigger will never be affected by volumes.", MessageType.Info);
                }
                else if (mask == -1 || ((mask & 1) != 0))
                {
                    EditorGUILayout.HelpBox("Do not use \"Everything\" or \"Default\" as a layer mask as it will slow down the volume blending process! Put post-processing volumes in their own dedicated layer for best performances.", MessageType.Warning);
                }
            }
            EditorGUI.indentLevel--;

            EditorGUILayout.Space();

            EditorGUILayout.LabelField(EditorUtilities.GetContent("Anti-aliasing"), EditorStyles.boldLabel);
            {
                EditorGUI.indentLevel++;

                m_AntialiasingMode.intValue = EditorGUILayout.Popup("Mode", m_AntialiasingMode.intValue, s_AntialiasingMethodNames);

                if (m_AntialiasingMode.intValue == (int)PostProcessLayer.Antialiasing.TemporalAntialiasing)
                {
                    EditorGUILayout.PropertyField(m_TaaJitterSpread);
                    EditorGUILayout.PropertyField(m_TaaStationaryBlending);
                    EditorGUILayout.PropertyField(m_TaaMotionBlending);
                    EditorGUILayout.PropertyField(m_TaaSharpen);
                }
            }
            EditorGUI.indentLevel--;

            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(m_ShowDebugUI);

            if (m_ShowDebugUI.boolValue)
            {
                EditorGUI.indentLevel++;
                {
                    EditorGUILayout.PropertyField(m_DebugMonitor);
                    EditorGUILayout.HelpBox("The debug UI only works on compute-shader enabled platforms.", MessageType.Info);
                    EditorGUILayout.HelpBox("Currently non-implemented.", MessageType.Warning);
                }
                EditorGUI.indentLevel--;
            }

            serializedObject.ApplyModifiedProperties();
        }