bool ITerrainLayerCustomUI.OnTerrainLayerGUI(TerrainLayer terrainLayer, Terrain terrain)
        {
            var terrainLayers = terrain.terrainData.terrainLayers;

            if (!DoesTerrainUseMaskMaps(terrainLayers))
            {
                return(false);
            }

            // Don't use the member field enableHeightBlend as ShaderGUI.OnGUI might not be called if the material UI is folded.
            bool heightBlend = terrain.materialTemplate.HasProperty(kEnableHeightBlend) && terrain.materialTemplate.GetFloat(kEnableHeightBlend) > 0;

            terrainLayer.diffuseTexture = EditorGUILayout.ObjectField(styles.diffuseTexture, terrainLayer.diffuseTexture, typeof(Texture2D), false) as Texture2D;
            TerrainLayerUtility.ValidateDiffuseTextureUI(terrainLayer.diffuseTexture);

            var diffuseRemapMin = terrainLayer.diffuseRemapMin;
            var diffuseRemapMax = terrainLayer.diffuseRemapMax;

            EditorGUI.BeginChangeCheck();

            bool enableDensity = false;

            if (terrainLayer.diffuseTexture != null)
            {
                var rect = GUILayoutUtility.GetLastRect();
                rect.y     += 16 + 4;
                rect.width  = EditorGUIUtility.labelWidth + 64;
                rect.height = 16;

                ++EditorGUI.indentLevel;

                var diffuseTint = new Color(diffuseRemapMax.x, diffuseRemapMax.y, diffuseRemapMax.z);
                diffuseTint       = EditorGUI.ColorField(rect, styles.colorTint, diffuseTint, true, false, false);
                diffuseRemapMax.x = diffuseTint.r;
                diffuseRemapMax.y = diffuseTint.g;
                diffuseRemapMax.z = diffuseTint.b;
                diffuseRemapMin.x = diffuseRemapMin.y = diffuseRemapMin.z = 0;

                if (!heightBlend)
                {
                    rect.y        = rect.yMax + 2;
                    enableDensity = EditorGUI.Toggle(rect, styles.opacityAsDensity, diffuseRemapMin.w > 0);
                }

                --EditorGUI.indentLevel;
            }
            diffuseRemapMax.w = 1;
            diffuseRemapMin.w = enableDensity ? 1 : 0;

            if (EditorGUI.EndChangeCheck())
            {
                terrainLayer.diffuseRemapMin = diffuseRemapMin;
                terrainLayer.diffuseRemapMax = diffuseRemapMax;
            }

            terrainLayer.normalMapTexture = EditorGUILayout.ObjectField(styles.normalMapTexture, terrainLayer.normalMapTexture, typeof(Texture2D), false) as Texture2D;
            TerrainLayerUtility.ValidateNormalMapTextureUI(terrainLayer.normalMapTexture, TerrainLayerUtility.CheckNormalMapTextureType(terrainLayer.normalMapTexture));

            if (terrainLayer.normalMapTexture != null)
            {
                var rect = GUILayoutUtility.GetLastRect();
                rect.y     += 16 + 4;
                rect.width  = EditorGUIUtility.labelWidth + 64;
                rect.height = 16;

                ++EditorGUI.indentLevel;
                terrainLayer.normalScale = EditorGUI.FloatField(rect, styles.normalScale, terrainLayer.normalScale);
                --EditorGUI.indentLevel;
            }

            terrainLayer.maskMapTexture = EditorGUILayout.ObjectField(heightBlend ? styles.maskMapTexture : styles.maskMapTextureWithoutHeight, terrainLayer.maskMapTexture, typeof(Texture2D), false) as Texture2D;
            TerrainLayerUtility.ValidateMaskMapTextureUI(terrainLayer.maskMapTexture);

            var maskMapRemapMin = terrainLayer.maskMapRemapMin;
            var maskMapRemapMax = terrainLayer.maskMapRemapMax;

            ++EditorGUI.indentLevel;
            EditorGUI.BeginChangeCheck();

            m_ShowChannelRemapping = EditorGUILayout.Foldout(m_ShowChannelRemapping, terrainLayer.maskMapTexture != null ? s_Styles.channelRemapping : s_Styles.defaultValues);
            if (m_ShowChannelRemapping)
            {
                if (terrainLayer.maskMapTexture != null)
                {
                    float min, max;
                    min = maskMapRemapMin.x; max = maskMapRemapMax.x;
                    EditorGUILayout.MinMaxSlider(s_Styles.metallic, ref min, ref max, 0, 1);
                    maskMapRemapMin.x = min; maskMapRemapMax.x = max;

                    min = maskMapRemapMin.y; max = maskMapRemapMax.y;
                    EditorGUILayout.MinMaxSlider(s_Styles.ao, ref min, ref max, 0, 1);
                    maskMapRemapMin.y = min; maskMapRemapMax.y = max;

                    if (heightBlend)
                    {
                        EditorGUILayout.LabelField(styles.height);
                        ++EditorGUI.indentLevel;
                        m_HeightParametrization = (HeightParametrization)EditorGUILayout.EnumPopup(styles.heightParametrization, m_HeightParametrization);
                        if (m_HeightParametrization == HeightParametrization.Amplitude)
                        {
                            // (height - heightBase) * amplitude
                            float amplitude  = Mathf.Max(maskMapRemapMax.z - maskMapRemapMin.z, Mathf.Epsilon); // to avoid divide by zero
                            float heightBase = -maskMapRemapMin.z / amplitude;
                            amplitude         = EditorGUILayout.FloatField(styles.heightAmplitude, amplitude * 100) / 100;
                            heightBase        = EditorGUILayout.FloatField(styles.heightBase, heightBase);
                            maskMapRemapMin.z = -heightBase * amplitude;
                            maskMapRemapMax.z = (1 - heightBase) * amplitude;
                        }
                        else
                        {
                            maskMapRemapMin.z = EditorGUILayout.FloatField(styles.heightMin, maskMapRemapMin.z * 100) / 100;
                            maskMapRemapMax.z = EditorGUILayout.FloatField(styles.heightMax, maskMapRemapMax.z * 100) / 100;
                        }
                        --EditorGUI.indentLevel;
                    }

                    min = maskMapRemapMin.w; max = maskMapRemapMax.w;
                    EditorGUILayout.MinMaxSlider(s_Styles.smoothness, ref min, ref max, 0, 1);
                    maskMapRemapMin.w = min; maskMapRemapMax.w = max;
                }
                else
                {
                    maskMapRemapMin.x = maskMapRemapMax.x = EditorGUILayout.Slider(s_Styles.metallic, maskMapRemapMin.x, 0, 1);
                    maskMapRemapMin.y = maskMapRemapMax.y = EditorGUILayout.Slider(s_Styles.ao, maskMapRemapMin.y, 0, 1);
                    if (heightBlend)
                    {
                        maskMapRemapMin.z = maskMapRemapMax.z = EditorGUILayout.FloatField(s_Styles.heightCm, maskMapRemapMin.z * 100) / 100;
                    }
                    maskMapRemapMin.w = maskMapRemapMax.w = EditorGUILayout.Slider(s_Styles.smoothness, maskMapRemapMin.w, 0, 1);
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                terrainLayer.maskMapRemapMin = maskMapRemapMin;
                terrainLayer.maskMapRemapMax = maskMapRemapMax;
            }
            --EditorGUI.indentLevel;

            EditorGUILayout.Space();
            TerrainLayerUtility.TilingSettingsUI(terrainLayer);

            return(true);
        }
Ejemplo n.º 2
0
        bool ITerrainLayerCustomUI.OnTerrainLayerGUI(TerrainLayer terrainLayer, Terrain terrain)
        {
            var terrainLayers = terrain.terrainData.terrainLayers;

            if (!DoesTerrainUseMaskMaps(terrainLayers))
            {
                return(false);
            }

            // Don't use the member field enableHeightBlend as ShaderGUI.OnGUI might not be called if the material UI is folded.
            bool heightBlend = terrain.materialTemplate.HasProperty(kEnableHeightBlend) && terrain.materialTemplate.GetFloat(kEnableHeightBlend) > 0;

            terrainLayer.diffuseTexture = EditorGUILayout.ObjectField(styles.diffuseTexture, terrainLayer.diffuseTexture, typeof(Texture2D), false) as Texture2D;
            TerrainLayerUtility.ValidateDiffuseTextureUI(terrainLayer.diffuseTexture);

            var diffuseRemapMin = terrainLayer.diffuseRemapMin;
            var diffuseRemapMax = terrainLayer.diffuseRemapMax;

            EditorGUI.BeginChangeCheck();

            bool enableDensity = false;

            if (terrainLayer.diffuseTexture != null)
            {
                var rect = GUILayoutUtility.GetLastRect();
                rect.y     += 16 + 4;
                rect.width  = EditorGUIUtility.labelWidth + 64;
                rect.height = 16;

                ++EditorGUI.indentLevel;

                var diffuseTint = new Color(diffuseRemapMax.x, diffuseRemapMax.y, diffuseRemapMax.z);
                diffuseTint       = EditorGUI.ColorField(rect, styles.colorTint, diffuseTint, true, false, false);
                diffuseRemapMax.x = diffuseTint.r;
                diffuseRemapMax.y = diffuseTint.g;
                diffuseRemapMax.z = diffuseTint.b;
                diffuseRemapMin.x = diffuseRemapMin.y = diffuseRemapMin.z = 0;

                if (!heightBlend)
                {
                    rect.y        = rect.yMax + 2;
                    enableDensity = EditorGUI.Toggle(rect, styles.opacityAsDensity, diffuseRemapMin.w > 0);
                }

                --EditorGUI.indentLevel;
            }
            diffuseRemapMax.w = 1;
            diffuseRemapMin.w = enableDensity ? 1 : 0;

            if (EditorGUI.EndChangeCheck())
            {
                terrainLayer.diffuseRemapMin = diffuseRemapMin;
                terrainLayer.diffuseRemapMax = diffuseRemapMax;
            }

            terrainLayer.normalMapTexture = EditorGUILayout.ObjectField(styles.normalMapTexture, terrainLayer.normalMapTexture, typeof(Texture2D), false) as Texture2D;
            TerrainLayerUtility.ValidateNormalMapTextureUI(terrainLayer.normalMapTexture, TerrainLayerUtility.CheckNormalMapTextureType(terrainLayer.normalMapTexture));

            if (terrainLayer.normalMapTexture != null)
            {
                var rect = GUILayoutUtility.GetLastRect();
                rect.y     += 16 + 4;
                rect.width  = EditorGUIUtility.labelWidth + 64;
                rect.height = 16;

                ++EditorGUI.indentLevel;
                terrainLayer.normalScale = EditorGUI.FloatField(rect, styles.normalScale, terrainLayer.normalScale);
                --EditorGUI.indentLevel;
            }

            terrainLayer.maskMapTexture = EditorGUILayout.ObjectField(heightBlend ? styles.maskMapTexture : styles.maskMapTextureWithoutHeight, terrainLayer.maskMapTexture, typeof(Texture2D), false) as Texture2D;
            TerrainLayerUtility.ValidateMaskMapTextureUI(terrainLayer.maskMapTexture);

            var maskMapRemapMin = terrainLayer.maskMapRemapMin;
            var maskMapRemapMax = terrainLayer.maskMapRemapMax;
            var smoothness      = terrainLayer.smoothness;
            var metallic        = terrainLayer.metallic;

            ++EditorGUI.indentLevel;
            EditorGUI.BeginChangeCheck();

            m_ShowChannelRemapping = EditorGUILayout.Foldout(m_ShowChannelRemapping, terrainLayer.maskMapTexture != null ? s_Styles.channelRemapping : s_Styles.defaultValues);
            if (m_ShowChannelRemapping)
            {
                if (terrainLayer.maskMapTexture != null)
                {
                    float min, max;
                    min = maskMapRemapMin.x; max = maskMapRemapMax.x;
                    EditorGUILayout.MinMaxSlider(s_Styles.metallic, ref min, ref max, 0, 1);
                    maskMapRemapMin.x = min; maskMapRemapMax.x = max;

                    min = maskMapRemapMin.y; max = maskMapRemapMax.y;
                    EditorGUILayout.MinMaxSlider(s_Styles.ao, ref min, ref max, 0, 1);
                    maskMapRemapMin.y = min; maskMapRemapMax.y = max;

                    if (heightBlend)
                    {
                        EditorGUILayout.LabelField(styles.height);
                        ++EditorGUI.indentLevel;
                        m_HeightParametrization = (HeightParametrization)EditorGUILayout.EnumPopup(styles.heightParametrization, m_HeightParametrization);
                        if (m_HeightParametrization == HeightParametrization.Amplitude)
                        {
                            // (height - heightBase) * amplitude
                            float amplitude  = Mathf.Max(maskMapRemapMax.z - maskMapRemapMin.z, Mathf.Epsilon); // to avoid divide by zero
                            float heightBase = -maskMapRemapMin.z / amplitude;
                            amplitude         = EditorGUILayout.FloatField(styles.heightAmplitude, amplitude * 100) / 100;
                            heightBase        = EditorGUILayout.FloatField(styles.heightBase, heightBase * 100) / 100;
                            maskMapRemapMin.z = heightBase * amplitude;
                            maskMapRemapMax.z = (1 - heightBase) * amplitude;
                        }
                        else
                        {
                            maskMapRemapMin.z = EditorGUILayout.FloatField(styles.heightMin, maskMapRemapMin.z * 100) / 100;
                            maskMapRemapMax.z = EditorGUILayout.FloatField(styles.heightMax, maskMapRemapMax.z * 100) / 100;
                        }
                        --EditorGUI.indentLevel;
                    }

                    min = maskMapRemapMin.w; max = maskMapRemapMax.w;
                    EditorGUILayout.MinMaxSlider(s_Styles.smoothness, ref min, ref max, 0, 1);
                    maskMapRemapMin.w = min; maskMapRemapMax.w = max;
                }
                else
                {
                    metallic = EditorGUILayout.Slider(s_Styles.metallic, metallic, 0, 1);
                    // AO and Height are still exclusively controlled via the maskRemap controls
                    // metallic and smoothness have their own values as fields within the LayerData.
                    maskMapRemapMax.y = EditorGUILayout.Slider(s_Styles.ao, maskMapRemapMax.y, 0, 1);

                    if (heightBlend)
                    {
                        maskMapRemapMax.z = EditorGUILayout.FloatField(s_Styles.heightCm, maskMapRemapMax.z * 100) / 100;
                    }
                    // There's a possibility that someone could slide max below the existing min value
                    // so we'll just protect against that by locking the min value down a little bit.
                    // In the case of height (Z), we are trying to set min to no lower than zero value unless
                    // max goes negative.  Zero is a good sensible value for the minimum.  For AO (Y), we
                    // don't need this extra protection step because the UI blocks us from going negative
                    // anyway.  In both cases, pushing the slider below the min value will lock them together,
                    // but min will be "left behind" if you go back up.
                    maskMapRemapMin.y = Mathf.Min(maskMapRemapMin.y, maskMapRemapMax.y);
                    maskMapRemapMin.z = Mathf.Min(Mathf.Max(0, maskMapRemapMin.z), maskMapRemapMax.z);

                    if (TextureHasAlpha(terrainLayer.diffuseTexture))
                    {
                        GUIStyle warnStyle = new GUIStyle(GUI.skin.label);
                        warnStyle.wordWrap = true;
                        GUILayout.Label("Smoothness is controlled by diffuse alpha channel", warnStyle);
                    }
                    else
                    {
                        smoothness = EditorGUILayout.Slider(s_Styles.smoothness, smoothness, 0, 1);
                    }
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                terrainLayer.maskMapRemapMin = maskMapRemapMin;
                terrainLayer.maskMapRemapMax = maskMapRemapMax;
                terrainLayer.smoothness      = smoothness;
                terrainLayer.metallic        = metallic;
            }
            --EditorGUI.indentLevel;

            EditorGUILayout.Space();
            TerrainLayerUtility.TilingSettingsUI(terrainLayer);

            return(true);
        }
        public override void OnInspectorGUI(Terrain terrain, IOnInspectorGUI editContext)
        {
            GUILayout.Label("Settings", EditorStyles.boldLabel);

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.Space();
            Editor.DrawFoldoutInspector(terrain.materialTemplate, ref m_TemplateMaterialEditor);

            EditorGUILayout.Space();

            int layerIndex = TerrainPaintUtility.FindTerrainLayerIndex(terrain, m_SelectedTerrainLayer);

            layerIndex = TerrainLayerUtility.ShowTerrainLayersSelectionHelper(terrain, layerIndex);
            EditorGUILayout.Space();

            if (EditorGUI.EndChangeCheck())
            {
                m_SelectedTerrainLayer = layerIndex != -1 ? terrain.terrainData.terrainLayers[layerIndex] : null;
                Save(true);
            }

            TerrainLayerUtility.ShowTerrainLayerGUI(terrain, m_SelectedTerrainLayer, ref m_SelectedTerrainLayerInspector,
                                                    (m_TemplateMaterialEditor as MaterialEditor)?.customShaderGUI as ITerrainLayerCustomUI);
            EditorGUILayout.Space();

            editContext.ShowBrushesGUI(5);



            if (layerIndex < 0)
            {
                return;
            }



            //  load SplatPaintRules (ScriptableObeject)  //
            {
                string name   = "SplatPaintRules_" + terrain.terrainData.terrainLayers[layerIndex].name + ".asset";
                string folder = "Assets/Terrain Tool Extender/SplatPaintRules";

                if (!AssetDatabase.IsValidFolder("Assets/Terrain Tool Extender"))
                {
                    AssetDatabase.CreateFolder("Assets", "Terrain Tool Extender");
                    AssetDatabase.CreateFolder("Assets/Terrain Tool Extender", "SplatPaintRules");
                    splatPaintRules = (CustomTerrainTools_SplatPaintRules)ScriptableObject.CreateInstance("CustomTerrainTools_SplatPaintRules");
                    AssetDatabase.CreateAsset(splatPaintRules, folder + "/" + name);
                }

                if (!AssetDatabase.IsValidFolder("Assets/Terrain Tool Extender/SplatPaintRules"))
                {
                    AssetDatabase.CreateFolder("Assets/Terrain Tool Extender", "SplatPaintRules");
                    splatPaintRules = (CustomTerrainTools_SplatPaintRules)ScriptableObject.CreateInstance("CustomTerrainTools_SplatPaintRules");
                    AssetDatabase.CreateAsset(splatPaintRules, folder + "/" + name);
                }

                splatPaintRules = (CustomTerrainTools_SplatPaintRules)AssetDatabase.LoadAssetAtPath(folder + "/" + name, typeof(CustomTerrainTools_SplatPaintRules));

                if (splatPaintRules == null)
                {
                    splatPaintRules = (CustomTerrainTools_SplatPaintRules)ScriptableObject.CreateInstance("CustomTerrainTools_SplatPaintRules");
                    AssetDatabase.CreateAsset(splatPaintRules, folder + "/" + name);;
                    splatPaintRules.SetMaxHeights(terrain.terrainData.size.y);
                    splatPaintRules.SetDirty();
                    MarkSceneDirty(terrain.gameObject);
                }
            }



            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            EditorGUILayout.BeginHorizontal();
            splatPaintRules.applyHeightRule = EditorGUILayout.Toggle("Apply Height Rule", splatPaintRules.applyHeightRule);
            EditorGUILayout.EndHorizontal();

            if (splatPaintRules.applyHeightRule)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Height : Min(start - end) -- Max(start - end)");
                splatPaintRules.minHeightStart = EditorGUILayout.DelayedFloatField(splatPaintRules.minHeightStart);
                if (splatPaintRules.useHeightTransition)
                {
                    splatPaintRules.minHeightEnd   = EditorGUILayout.DelayedFloatField(splatPaintRules.minHeightEnd);
                    splatPaintRules.maxHeightStart = EditorGUILayout.DelayedFloatField(splatPaintRules.maxHeightStart);
                }
                splatPaintRules.maxHeightEnd = EditorGUILayout.DelayedFloatField(splatPaintRules.maxHeightEnd);
                EditorGUILayout.EndHorizontal();


                if (splatPaintRules.useHeightTransition)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.MinMaxSlider(ref splatPaintRules.minHeightEnd, ref splatPaintRules.maxHeightStart, 0f, terrain.terrainData.size.y);
                    EditorGUILayout.EndHorizontal();
                    splatPaintRules.minHeightEnd   = Mathf.Max(splatPaintRules.minHeightEnd, splatPaintRules.minHeightStart);
                    splatPaintRules.maxHeightStart = Mathf.Min(splatPaintRules.maxHeightStart, splatPaintRules.maxHeightEnd);
                }
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.MinMaxSlider(ref splatPaintRules.minHeightStart, ref splatPaintRules.maxHeightEnd, 0f, terrain.terrainData.size.y);
                EditorGUILayout.EndHorizontal();


                EditorGUILayout.BeginHorizontal();
                splatPaintRules.inverseHeightRule   = EditorGUILayout.Toggle("Inverse Height", splatPaintRules.inverseHeightRule);
                splatPaintRules.useHeightTransition = EditorGUILayout.Toggle("Height Transition", splatPaintRules.useHeightTransition);
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();



            EditorGUILayout.Space();


            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            EditorGUILayout.BeginHorizontal();
            splatPaintRules.applyAngleRule = EditorGUILayout.Toggle("Apply Angle Rule", splatPaintRules.applyAngleRule);
            EditorGUILayout.EndHorizontal();

            if (splatPaintRules.applyAngleRule)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Angle : Min(start - end) -- Max(start - end)");
                splatPaintRules.minAngleStart = EditorGUILayout.DelayedFloatField(splatPaintRules.minAngleStart);
                if (splatPaintRules.useAngleTransition)
                {
                    splatPaintRules.minAngleEnd   = EditorGUILayout.DelayedFloatField(splatPaintRules.minAngleEnd);
                    splatPaintRules.maxAngleStart = EditorGUILayout.DelayedFloatField(splatPaintRules.maxAngleStart);
                }
                splatPaintRules.maxAngleEnd = EditorGUILayout.DelayedFloatField(splatPaintRules.maxAngleEnd);
                EditorGUILayout.EndHorizontal();

                if (splatPaintRules.useAngleTransition)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.MinMaxSlider(ref splatPaintRules.minAngleEnd, ref splatPaintRules.maxAngleStart, 0f, 90f);
                    EditorGUILayout.EndHorizontal();
                    splatPaintRules.minAngleEnd   = Mathf.Max(splatPaintRules.minAngleEnd, splatPaintRules.minAngleStart);
                    splatPaintRules.maxAngleStart = Mathf.Min(splatPaintRules.maxAngleStart, splatPaintRules.maxAngleEnd);
                }

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.MinMaxSlider(ref splatPaintRules.minAngleStart, ref splatPaintRules.maxAngleEnd, 0f, 90f);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                splatPaintRules.inverseAngleRule   = EditorGUILayout.Toggle("Inverse Angle", splatPaintRules.inverseAngleRule);
                splatPaintRules.useAngleTransition = EditorGUILayout.Toggle("Angle Transition", splatPaintRules.useAngleTransition);
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();
            if (EditorGUI.EndChangeCheck())
            {
                splatPaintRules.SetDirty();
                MarkSceneDirty(terrain.gameObject);
            }

            selectedTerrainLayerIndex = layerIndex;

            splatPaintRules = (CustomTerrainTools_SplatPaintRules)EditorGUILayout.ObjectField(splatPaintRules, typeof(CustomTerrainTools_SplatPaintRules), true);
        }
Ejemplo n.º 4
0
            bool ITerrainLayerCustomUI.OnTerrainLayerGUI(TerrainLayer terrainLayer, Terrain terrain)
            {
                if (terrain.materialTemplate == null)
                {
                    return(false);
                }

                bool updatedTimestamp = SG2Timestamp != ShaderGenerator2.LastCompilationTimestamp;

                if (terrainShader != terrain.materialTemplate.shader || updatedTimestamp)
                {
                    SG2Timestamp  = ShaderGenerator2.LastCompilationTimestamp;
                    terrainShader = terrain.materialTemplate.shader;
                    FindUsedTerrainProperties(terrainShader);
                }

                if (currentTerrainLayer != terrainLayer || updatedTimestamp)
                {
                    currentTerrainLayer = terrainLayer;
                    foreach (var terrainLayerProperty in terrainLayerProperties)
                    {
                        terrainLayerProperty.FetchValuesFromTerrainLayer(currentTerrainLayer);
                    }
                }

                // Header
                var label = (Screen.width > 450f) ? "TOONY COLORS PRO 2 - Terrain Layer" : "TCP2 - Terrain Layer";

                TCP2_GUI.HeaderBig(label);

                // Diffuse texture
                terrainLayer.diffuseTexture = EditorGUILayout.ObjectField(TCP2_GUI.TempContent("Albedo"), terrainLayer.diffuseTexture, typeof(Texture2D), false) as Texture2D;
                TerrainLayerUtility.ValidateDiffuseTextureUI(terrainLayer.diffuseTexture);
                // TerrainLayerUtility.TilingSettingsUI(terrainLayer);

                TCP2_GUI.Header("Tiling Settings");
                terrainLayer.tileSize   = EditorGUILayout.Vector2Field(TCP2_GUI.TempContent("Size"), terrainLayer.tileSize);
                terrainLayer.tileOffset = EditorGUILayout.Vector2Field(TCP2_GUI.TempContent("Offset"), terrainLayer.tileOffset);

                GUILayout.Space(8f);

                // Custom properties
                if (terrainLayerProperties.Count > 0)
                {
                    TCP2_GUI.Header("Custom Properties");
                    foreach (var terrainLayerProperty in terrainLayerProperties)
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            terrainLayerProperty.DrawGUI(terrainLayer);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(terrainLayer, "Change terrain layer properties");
                            terrainLayerProperty.TransferValueToTerrainLayer(terrainLayer);
                        }
                    }
                }

                return(true);
            }
Ejemplo n.º 5
0
        bool ITerrainLayerCustomUI.OnTerrainLayerGUI(TerrainLayer terrainLayer, Terrain terrain)
        {
            var terrainLayers = terrain.terrainData.terrainLayers;

            terrainLayer.diffuseTexture = EditorGUILayout.ObjectField(styles.diffuseTexture, terrainLayer.diffuseTexture, typeof(Texture2D), false) as Texture2D;
            // TerrainLayerUtility.ValidateDiffuseTextureUI(terrainLayer.diffuseTexture);

            var diffuseRemapMin = terrainLayer.diffuseRemapMin;
            var diffuseRemapMax = terrainLayer.diffuseRemapMax;

            EditorGUI.BeginChangeCheck();

            bool enableDensity = false;

            if (terrainLayer.diffuseTexture != null)
            {
                var rect = GUILayoutUtility.GetLastRect();
                rect.y     += 16 + 4;
                rect.width  = EditorGUIUtility.labelWidth + 64;
                rect.height = 16;

                ++EditorGUI.indentLevel;

                var diffuseTint = new Color(diffuseRemapMax.x, diffuseRemapMax.y, diffuseRemapMax.z);
                diffuseTint       = EditorGUI.ColorField(rect, styles.colorTint, diffuseTint, true, false, false);
                diffuseRemapMax.x = diffuseTint.r;
                diffuseRemapMax.y = diffuseTint.g;
                diffuseRemapMax.z = diffuseTint.b;
                diffuseRemapMin.x = diffuseRemapMin.y = diffuseRemapMin.z = 0;

                // enableDensity = diffuseRemapMin.w > 0;

                // For now, disable the enableDensity toggle, until we fully understand the feature and can test against expectation.
                // if (!heightBlend)
                // {
                //     rect.y = rect.yMax + 2;
                //     enableDensity = EditorGUI.Toggle(rect, styles.opacityAsDensity, diffuseRemapMin.w > 0);
                // }

                if (materialEditor != null)
                {
                    Material material = materialEditor.target as Material;
                    DrawTextureFilterModeErrorMessagesForTexture(material, materialEditor, terrainLayer.diffuseTexture, "Terrain Layer Diffuse Texture");
                }

                --EditorGUI.indentLevel;
            }
            diffuseRemapMax.w = 1;
            diffuseRemapMin.w = enableDensity ? 1 : 0;

            if (EditorGUI.EndChangeCheck())
            {
                terrainLayer.diffuseRemapMin = diffuseRemapMin;
                terrainLayer.diffuseRemapMax = diffuseRemapMax;
            }

            EditorGUILayout.Space();
            TerrainLayerUtility.TilingSettingsUI(terrainLayer);

            return(true);
        }
        public override void OnInspectorGUI(Terrain terrain, IOnInspectorGUI editContext)
        {
            GUILayout.Label("Settings", EditorStyles.boldLabel);

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.Space();
            if (m_TemplateMaterialEditor != null && m_TemplateMaterialEditor.target != terrain.materialTemplate)
            {
                UnityEngine.Object.DestroyImmediate(m_TemplateMaterialEditor);
                m_TemplateMaterialEditor = null;
            }
            if (m_TemplateMaterialEditor == null && terrain.materialTemplate != null)
            {
                m_TemplateMaterialEditor = Editor.CreateEditor(terrain.materialTemplate) as MaterialEditor;
                m_TemplateMaterialEditor.firstInspectedEditor = true;
            }

            if (m_TemplateMaterialEditor != null)
            {
                DrawFoldoutEditor(m_TemplateMaterialEditor, kTemplateMaterialEditorControl, ref m_ShowMaterialEditor);
                EditorGUILayout.Space();
            }

            int layerIndex = TerrainPaintUtility.FindTerrainLayerIndex(terrain, m_SelectedTerrainLayer);

            layerIndex = TerrainLayerUtility.ShowTerrainLayersSelectionHelper(terrain, layerIndex);
            EditorGUILayout.Space();

            if (EditorGUI.EndChangeCheck())
            {
                if (layerIndex != -1)
                {
                    m_SelectedTerrainLayer = terrain.terrainData.terrainLayers[layerIndex];
                }
                else
                {
                    m_SelectedTerrainLayer = null;
                }

                if (m_SelectedTerrainLayerInspector != null)
                {
                    UnityEngine.Object.DestroyImmediate(m_SelectedTerrainLayerInspector);
                    m_SelectedTerrainLayerInspector = null;
                }
                if (m_SelectedTerrainLayer != null)
                {
                    m_SelectedTerrainLayerInspector = Editor.CreateEditor(m_SelectedTerrainLayer) as TerrainLayerInspector;
                }

                Save(true);
            }

            if (m_SelectedTerrainLayerInspector != null)
            {
                var terrainLayerCustomUI = m_TemplateMaterialEditor?.m_CustomShaderGUI as ITerrainLayerCustomUI;
                if (terrainLayerCustomUI != null)
                {
                    m_SelectedTerrainLayerInspector.SetCustomUI(terrainLayerCustomUI, terrain);
                }

                DrawFoldoutEditor(m_SelectedTerrainLayerInspector, kSelectedTerrainLayerEditorControl, ref m_ShowLayerEditor);
                EditorGUILayout.Space();
            }
            editContext.ShowBrushesGUI(5);
        }