private void DrawRendererFeature(int index, ref SerializedProperty prop)
        {
            var obj   = prop.objectReferenceValue;
            var title = ObjectNames.GetInspectorTitle(obj);

            if (obj != null)
            {
                var editor            = CreateEditor(obj);
                var serializedFeature = new SerializedObject(obj);
                // Foldout header
                EditorGUI.BeginChangeCheck();
                var displayContent = CoreEditorUtils.DrawHeaderToggle(
                    title,
                    prop,
                    serializedFeature.FindProperty("m_Active"),
                    pos => OnContextClick(pos, index)
                    );
                if (EditorGUI.EndChangeCheck())
                {
                    m_SaveAsset = true;
                }

                // ObjectEditor
                if (displayContent)
                {
                    EditorGUI.BeginChangeCheck();
                    var propertyName = serializedFeature.FindProperty("m_Name");
                    propertyName.stringValue = ValidateName(EditorGUILayout.DelayedTextField(Styles.PassNameField, propertyName.stringValue));
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_SaveAsset = true;
                    }
                    editor.DrawDefaultInspector();
                }

                //Save the changed data
                if (!serializedFeature.hasModifiedProperties)
                {
                    return;
                }
                serializedFeature.ApplyModifiedProperties();
                m_SaveAsset = true;
            }
            else
            {
                CoreEditorUtils.DrawHeaderToggle(
                    Styles.MissingFeature,
                    prop,
                    m_FalseBool,
                    pos => OnContextClick(pos, index)
                    );
                m_FalseBool.boolValue = false; // always make sure false bool is false
                EditorGUILayout.HelpBox(Styles.MissingFeature.tooltip, MessageType.Error);
                if (GUILayout.Button("Attempt Fix", EditorStyles.miniButton))
                {
                    var data = target as ScriptableRendererData;
                    data.ValidateRendererFeatures();
                }
            }
        }
Example #2
0
        private void DrawRendererFeature(int index, ref SerializedProperty renderFeatureProperty)
        {
            Object rendererFeatureObjRef = renderFeatureProperty.objectReferenceValue;

            if (rendererFeatureObjRef != null)
            {
                bool   hasChangedProperties = false;
                string title = ObjectNames.GetInspectorTitle(rendererFeatureObjRef);

                // Get the serialized object for the editor script & update it
                Editor           rendererFeatureEditor            = m_Editors[index];
                SerializedObject serializedRendererFeaturesEditor = rendererFeatureEditor.serializedObject;
                serializedRendererFeaturesEditor.Update();

                // Foldout header
                EditorGUI.BeginChangeCheck();
                SerializedProperty activeProperty = serializedRendererFeaturesEditor.FindProperty("m_Active");
                bool displayContent = CoreEditorUtils.DrawHeaderToggle(title, renderFeatureProperty, activeProperty, pos => OnContextClick(pos, index));
                hasChangedProperties |= EditorGUI.EndChangeCheck();

                // ObjectEditor
                if (displayContent)
                {
                    EditorGUI.BeginChangeCheck();
                    SerializedProperty nameProperty = serializedRendererFeaturesEditor.FindProperty("m_Name");
                    nameProperty.stringValue = ValidateName(EditorGUILayout.DelayedTextField(Styles.PassNameField, nameProperty.stringValue));
                    hasChangedProperties    |= EditorGUI.EndChangeCheck();

                    EditorGUI.BeginChangeCheck();
                    rendererFeatureEditor.OnInspectorGUI();
                    hasChangedProperties |= EditorGUI.EndChangeCheck();

                    EditorGUILayout.Space(EditorGUIUtility.singleLineHeight);
                }

                // Apply changes and save if the user has modified any settings
                if (hasChangedProperties)
                {
                    serializedRendererFeaturesEditor.ApplyModifiedProperties();
                    serializedObject.ApplyModifiedProperties();
                    ForceSave();
                }
            }
            else
            {
                CoreEditorUtils.DrawHeaderToggle(Styles.MissingFeature, renderFeatureProperty, m_FalseBool, pos => OnContextClick(pos, index));
                m_FalseBool.boolValue = false; // always make sure false bool is false
                EditorGUILayout.HelpBox(Styles.MissingFeature.tooltip, MessageType.Error);
                if (GUILayout.Button("Attempt Fix", EditorStyles.miniButton))
                {
                    ScriptableRendererData data = target as ScriptableRendererData;
                    data.ValidateRendererFeatures();
                }
            }
        }
Example #3
0
        private void DrawBuildFeature(int index, ref SerializedProperty prop)
        {
            Object obj   = prop.objectReferenceValue;
            string title = ObjectNames.GetInspectorTitle(obj);

            if (obj != null)
            {
                var serializedFeature = new SerializedObject(obj);

                EditorGUI.BeginChangeCheck();
                bool displayContent = CoreEditorUtils.DrawHeaderToggle(title, prop, serializedFeature.FindProperty("_isActive"), pos => OnContextClick(pos, index));
                if (EditorGUI.EndChangeCheck())
                {
                    SetNeedsSave();
                }

                if (displayContent)
                {
                    GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);

                    EditorGUI.BeginChangeCheck();
                    var propertyName = serializedFeature.FindProperty("m_Name");
                    propertyName.stringValue = ValidateName(EditorGUILayout.DelayedTextField(Styles.featureNameField, propertyName.stringValue));
                    if (EditorGUI.EndChangeCheck())
                    {
                        SetNeedsSave();
                    }

                    GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
                    var editor = CreateEditor(obj);
                    editor.OnInspectorGUI();
                }

                if (serializedFeature.hasModifiedProperties)
                {
                    serializedFeature.ApplyModifiedProperties();
                    SetNeedsSave();
                }
            }
        }
Example #4
0
    void ShowPropertyBinderEditor(int index)
    {
        var prop   = _binders.GetArrayElementAtIndex(index);
        var finder = new RelativePropertyFinder(prop);

        // Header
        CoreEditorUtils.DrawSplitter();

        var toggle = CoreEditorUtils.DrawHeaderToggle
                         (PropertyBinderNameUtil.Shorten(prop),
                         prop, finder["Enabled"],
                         pos => CreateHeaderContextMenu(index)
                         .DropDown(new Rect(pos, Vector2.zero)));

        if (!toggle)
        {
            return;
        }

        _binders.serializedObject.Update();
        EditorGUILayout.Space();

        // Properties
        var target = finder["Target"];

        EditorGUILayout.PropertyField(target);

        if (ComponentSelector.GetInstance(target).ShowGUI(target) &&
            PropertySelector.GetInstance(target, finder["_propertyType"])
            .ShowGUI(finder["PropertyName"]))
        {
            // EditorGUILayout.PropertyField(finder["Value0"], Styles.Value0);
            // EditorGUILayout.PropertyField(finder["Value1"], Styles.Value1);
        }

        _binders.serializedObject.ApplyModifiedProperties();
        EditorGUILayout.Space();
    }
Example #5
0
        void DrawSections()
        {
            if (!stylizedWater.meshRenderer || !stylizedWater.meshRenderer.sharedMaterial || !stylizedWater.meshRenderer.enabled)
            {
                EditorGUILayout.Space();
                EditorGUILayout.HelpBox("Object has no active mesh renderer and/or material. Please add those first.", MessageType.Warning);
                EditorGUILayout.Space();
                return;
            }

            string name = stylizedWater.meshRenderer.sharedMaterial.shader.name;

            if (name != shaderName && name != mobileShaderName && name != underwaterShaderName)
            {
                EditorGUILayout.Space();
                EditorGUILayout.HelpBox("Material incompatible. You should add a material that uses the Stylized Water shader.", MessageType.Warning);
                EditorGUILayout.Space();
                return;
            }

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            EditorGUILayout.Space();
            switch (name)
            {
            case shaderName: EditorGUILayout.LabelField("   " + stylizedWater.material.name); break;

            case mobileShaderName: EditorGUILayout.LabelField("   " + stylizedWater.material.name + " (Mobile Variant)"); break;

            case underwaterShaderName: EditorGUILayout.LabelField("   " + stylizedWater.material.name + " (Underwater Variant)"); break;
            }
            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            CoreEditorUtils.DrawSplitter();

            if (name == shaderName || name == mobileShaderName)
            {
                colorTransparencySettings = CoreEditorUtils.DrawHeaderFoldout("Colors and Transparency", colorTransparencySettings, false, (Func <bool>)null, null);
                DrawPropertiesInspector(colorTransparencySettings, DrawColorSettings);

                DrawPropertiesInspector(CoreEditorUtils.DrawHeaderToggle(EditorGUIUtility.TrTextContent("Surface Foam"), surfaceFoamExpanded, enableSurfaceFoam, null), DrawSurfaceFoamSettings);

                DrawPropertiesInspector(CoreEditorUtils.DrawHeaderToggle(EditorGUIUtility.TrTextContent("Intersection Effects"), intersectionEffectsExpanded, enableIntersectionEffects, null), DrawIntersectionEffectSettings);
            }

            if (name == shaderName)
            {
                DrawPropertiesInspector(CoreEditorUtils.DrawHeaderToggle(EditorGUIUtility.TrTextContent("Foam Shadows"), foamShadowsExpanded, enableFoamShadows, null), DrawFoamShadowSettings);

                causticsSettings = CoreEditorUtils.DrawHeaderFoldout("Caustics", causticsSettings, false, (Func <bool>)null, null);
                DrawPropertiesInspector(causticsSettings, DrawCausticsSettings);

                planarReflectionSettings = CoreEditorUtils.DrawHeaderFoldout("Planar Reflections", planarReflectionSettings, false, (Func <bool>)null, null);
                DrawPropertiesInspector(planarReflectionSettings, DrawPlanarReflectionSettings);

                surfaceSettings = CoreEditorUtils.DrawHeaderFoldout("Surface and Lighting", surfaceSettings, false, (Func <bool>)null, null);
                DrawPropertiesInspector(surfaceSettings, DrawSurfaceSettings);
            }

            if (name == mobileShaderName || name == underwaterShaderName)
            {
                DrawPropertiesInspector(CoreEditorUtils.DrawHeaderToggle(EditorGUIUtility.TrTextContent("Refraction"), refractionExpanded, enableRefraction, null), DrawRefractionSettings);
            }

            if (name == shaderName || name == mobileShaderName)
            {
                waveSettings = CoreEditorUtils.DrawHeaderFoldout("Waves", waveSettings, false, (Func <bool>)null, null);
                DrawPropertiesInspector(waveSettings, DrawWaveSettings);
            }

            if (name == shaderName || name == underwaterShaderName)
            {
                underwaterSettings = CoreEditorUtils.DrawHeaderFoldout("Underwater", underwaterSettings, false, (Func <bool>)null, null);
                DrawPropertiesInspector(underwaterSettings, DrawUnderwaterSettings);
            }

            additionalSettings = CoreEditorUtils.DrawHeaderFoldout("Additional Settings", additionalSettings, false, (Func <bool>)null, null);
            DrawPropertiesInspector(additionalSettings, DrawAdditionalSettings);

            EditorGUILayout.Space();
            if (stylizedWater.meshRenderer.shadowCastingMode == UnityEngine.Rendering.ShadowCastingMode.On)
            {
                CoreEditorUtils.DrawFixMeBox("Water is casting shadows. \nYou should turn this off.", () => TurnOffWaterShadowCasting());
            }
        }
Example #6
0
        public override void OnInspectorGUI()
        {
            if (!m_Target)
            {
                return;
            }

            using (new EditorGUILayout.HorizontalScope())
            {
                if (GUILayout.Button("Populate"))
                {
                    m_Target.Populate();
                }

                if (GUILayout.Button("Apply"))
                {
                    m_Target.Apply();
                }

                if (GUILayout.Button("Reset"))
                {
                    m_Target.Reset();
                    RefreshEditors();
                    Repaint();
                }
            }

            serializedObject.Update();

            if (m_Target.renderers.Length == 0)
            {
                EditorGUILayout.HelpBox($"{typeof(MaterialOverrideGroup)} contains no renderers.", MessageType.Info);
                return;
            }

            // Find null renderers
            var oldRenderers = new List <Renderer>();

            foreach (var renderer in m_Target.renderers)
            {
                if (renderer == null)
                {
                    continue;
                }

                oldRenderers.Add(renderer);
            }

            // Remove null renderers
            if (oldRenderers.Count != m_Renderers.arraySize)
            {
                m_Renderers.ClearArray();
                foreach (var renderer in oldRenderers)
                {
                    m_Renderers.arraySize += 1;
                    m_Renderers.GetArrayElementAtIndex(m_Renderers.arraySize - 1).objectReferenceValue = (Object)renderer;
                }
            }

            EditorGUI.BeginChangeCheck();

            CoreEditorUtils.DrawSplitter();
            m_ShaderOverridesFoldout.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_ShaderOverridesFoldout.value, "Shader Overrides");
            if (m_ShaderOverridesFoldout.value)
            {
                var targetShaders = m_Target.shaders;

                for (int i = 0, count = targetShaders.Length; i < count; i++)
                {
                    if (!m_Target.TryGetOverride(targetShaders[i], out var propertyOverrideList))
                    {
                        continue;
                    }

                    if (!m_ShaderOverrideEditors.TryGetValue(propertyOverrideList, out var editor))
                    {
                        continue;
                    }

                    // Draw material header
                    CoreEditorUtils.DrawSplitter();
                    bool displayContent = CoreEditorUtils.DrawHeaderToggle(
                        targetShaders[i].name,
                        editor.baseProperty,
                        editor.active,
                        null,
                        () => editor.showHidden,
                        () => editor.showHidden = !editor.showHidden
                        );

                    if (displayContent)
                    {
                        using (new EditorGUI.DisabledScope(!editor.active.boolValue))
                        {
                            editor.OnInspectorGUI();
                        }
                    }
                }

                if (m_Target.shaders.Length == 0)
                {
                    EditorGUILayout.HelpBox($"{typeof(MaterialOverrideGroup)} contains no shaders.", MessageType.Info);
                }
            }

            EditorGUILayout.EndFoldoutHeaderGroup();

            CoreEditorUtils.DrawSplitter();
            m_MaterialOverridesFoldout.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_MaterialOverridesFoldout.value, "Material Overrides");
            if (m_MaterialOverridesFoldout.value)
            {
                var targetMaterials = m_Target.materials;

                // Draw materials
                for (int i = 0, count = targetMaterials.Length; i < count; i++)
                {
                    if (!m_Target.TryGetOverride(targetMaterials[i], out var propertyOverrideList))
                    {
                        continue;
                    }

                    if (!m_ShaderOverrideEditors.TryGetValue(propertyOverrideList, out var editor))
                    {
                        continue;
                    }

                    // Draw material header
                    CoreEditorUtils.DrawSplitter();
                    bool displayContent = CoreEditorUtils.DrawHeaderToggle(
                        targetMaterials[i].name,
                        editor.baseProperty,
                        editor.active,
                        null,
                        () => editor.showHidden,
                        () => editor.showHidden = !editor.showHidden
                        );

                    if (displayContent)
                    {
                        using (new EditorGUI.DisabledScope(!editor.active.boolValue))
                        {
                            editor.OnInspectorGUI();
                        }
                    }
                }

                if (m_Target.materials.Length == 0)
                {
                    EditorGUILayout.HelpBox($"{typeof(MaterialOverrideGroup)} contains no materials.", MessageType.Info);
                }
            }

            EditorGUILayout.EndFoldoutHeaderGroup();

            serializedObject.ApplyModifiedProperties();

            if (EditorGUI.EndChangeCheck())
            {
                m_Target.Apply();
            }
        }