Exemple #1
0
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            this.FindProperties(props);

            this.m_MaterialEditor = materialEditor;

            //Style similar to Standard shader
            m_MaterialEditor.SetDefaultGUIWidths();
            m_MaterialEditor.UseDefaultMargins();
            EditorGUIUtility.labelWidth = 0f;

            EditorGUI.BeginChangeCheck();

            //Draw fields
            DoHeader();

            DoMapsArea();
            DoColorArea();

            if (EditorGUI.EndChangeCheck())
            {
                //Apply changes
            }

            GUIHelper.DrawExtraFields(m_MaterialEditor);

            if (showHelp)
            {
                GUIHelper.DrawWindInfo();
            }

            GUIHelper.DrawFooter();
        }
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            this.m_MaterialEditor = materialEditor;
            targetMat             = materialEditor.target as Material;

            this.FindProperties(props);

            //Style similar to Standard shader
            m_MaterialEditor.SetDefaultGUIWidths();
            m_MaterialEditor.UseDefaultMargins();
            EditorGUIUtility.labelWidth = 0f;

#if UNITY_2019_3_OR_NEWER
            if (UnityEngine.Rendering.GraphicsSettings.currentRenderPipeline != null &&
                !targetMat.shader.name.Contains("Universal Render Pipeline"))
            {
                EditorGUILayout.HelpBox("A render pipeline is in use, but this material is using a shader for the Built-in render pipeline.\n\nShaders and materials can be converted through the Help window", MessageType.Error);
                EditorGUILayout.Space();
            }
#endif

            EditorGUI.BeginChangeCheck();

            //Draw fields
            DoHeader();

            DoMapsArea();
            DoColorArea();

            if (EditorGUI.EndChangeCheck())
            {
                //Apply changes
            }

            GUILayout.Label("Advanced Options", EditorStyles.boldLabel);

            GUIHelper.DrawExtraFields(m_MaterialEditor);

            m_MaterialEditor.ShaderProperty(_UseSpeedTreeWind, new GUIContent("Sample SpeedTree wind"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("If this is a tree created using the SpeedTree Unity Modeler, this toggle will make the shader read the wind information as stored by SpeedTree.", MessageType.None);
            }

            if (showHelp)
            {
                GUIHelper.DrawWindInfo();
            }

            GUIHelper.DrawFooter();
        }
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if (windController == null)
            {
                LocateWindController();
            }

            //Receive
            visualizeVectors = WindController._visualizeVectors;

            this.m_MaterialEditor = materialEditor;
            targetMat             = (Material)materialEditor.target;

            this.FindProperties(props);

            //Style similar to Standard shader
            m_MaterialEditor.SetDefaultGUIWidths();
            m_MaterialEditor.UseDefaultMargins();
            EditorGUIUtility.labelWidth = 0f;

#if UNITY_2019_3_OR_NEWER
            if (UnityEngine.Rendering.GraphicsSettings.currentRenderPipeline != null &&
                !targetMat.shader.name.Contains("Universal Render Pipeline"))
            {
                EditorGUILayout.HelpBox("A render pipeline is in use, but this material is using a shader for the Built-in render pipeline.\n\nShaders and materials can be converted through the Help window", MessageType.Error);
                EditorGUILayout.Space();
            }
#endif

            EditorGUI.BeginChangeCheck();

            //Draw fields
            DoHeader();

            DoMapsArea();
            DoColorArea();
            DoAnimationArea();

            if (EditorGUI.EndChangeCheck())
            {
                //Send
                WindController.VisualizeVectors(visualizeVectors);
            }

            GUILayout.Label("Advanced Options", EditorStyles.boldLabel);

            GUIHelper.DrawExtraFields(m_MaterialEditor);

            GUIHelper.DrawFooter();
        }
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            this.FindProperties(props);

            this.m_MaterialEditor = materialEditor;

            //Style similar to Standard shader
            m_MaterialEditor.SetDefaultGUIWidths();
            m_MaterialEditor.UseDefaultMargins();
            EditorGUIUtility.labelWidth = 0f;

            EditorGUI.BeginChangeCheck();

            //Draw fields
            DoHeader();

            DoMapsArea();
            DoColorArea();

            if (EditorGUI.EndChangeCheck())
            {
                //Apply changes
            }

            GUILayout.Label("Advanced Options", EditorStyles.boldLabel);

            GUIHelper.DrawExtraFields(m_MaterialEditor);

            m_MaterialEditor.ShaderProperty(_UseSpeedTreeWind, new GUIContent("Sample SpeedTree wind"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("If this is a tree created using the SpeedTree Unity Modeler, this toggle will make the shader read the wind information as stored by SpeedTree.", MessageType.None);
            }

            EditorGUI.BeginDisabledGroup(_UseSpeedTreeWind.floatValue == 1);
            m_MaterialEditor.ShaderProperty(_UseLegacyVertexColors, new GUIContent("Legacy vertex color layout"));
            if (_UseSpeedTreeWind.floatValue == 0)
            {
                EditorGUILayout.HelpBox("Since version 1.2.1 the Blue and Alpha channel have been swapped. If your custom tree uses the old layout, check this.", MessageType.None);
            }
            EditorGUI.EndDisabledGroup();

            if (showHelp)
            {
                GUIHelper.DrawWindInfo();
            }

            GUIHelper.DrawFooter();
        }
Exemple #5
0
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if (windController == null)
            {
                LocateWindController();
            }
            this.FindProperties(props);

            //Receive
            visualizeVectors = WindController._visualizeVectors;

            this.m_MaterialEditor = materialEditor;

            //Style similar to Standard shader
            m_MaterialEditor.SetDefaultGUIWidths();
            m_MaterialEditor.UseDefaultMargins();
            EditorGUIUtility.labelWidth = 0f;

            EditorGUI.BeginChangeCheck();

            //Draw fields
            DoHeader();

            DoMapsArea();
            DoColorArea();
            DoAnimationArea();

            if (EditorGUI.EndChangeCheck())
            {
                //Send
                WindController.VisualizeVectors(visualizeVectors);
            }

            GUILayout.Label("Advanced Options", EditorStyles.boldLabel);

            GUIHelper.DrawExtraFields(m_MaterialEditor);

            EditorGUI.BeginDisabledGroup(_UseSpeedTreeWind.floatValue == 1);
            m_MaterialEditor.ShaderProperty(_UseLegacyVertexColors, new GUIContent("Legacy vertex color layout"));
            if (_UseSpeedTreeWind.floatValue == 0)
            {
                EditorGUILayout.HelpBox("Since version 1.2.1 the Blue and Alpha channel have been swapped. If your custom tree uses the old layout, check this.", MessageType.None);
            }
            EditorGUI.EndDisabledGroup();

            GUIHelper.DrawFooter();
        }
Exemple #6
0
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if (windController == null)
            {
                LocateWindController();
            }
            this.FindProperties(props);

            //Receive
            visualizeVectors = WindController._visualizeVectors;

            this.m_MaterialEditor = materialEditor;

            //Style similar to Standard shader
            m_MaterialEditor.SetDefaultGUIWidths();
            m_MaterialEditor.UseDefaultMargins();
            EditorGUIUtility.labelWidth = 0f;

            //GetGlobalTexture is only available since Unity 5.5
#if UNITY_5_5_OR_NEWER
            hasPigmentMap = (Shader.GetGlobalTexture("_PigmentMap")) ? true : false;
#endif

            EditorGUI.BeginChangeCheck();

            //Draw fields
            DoHeader();

            DoMapsArea();
            DoColorArea();
            DoAnimationArea();
            DoBendingArea();
            DoHeightmapArea();
            DoPigmentMapArea();

            if (EditorGUI.EndChangeCheck())
            {
                //Send
                WindController.VisualizeVectors(visualizeVectors);
            }

            GUIHelper.DrawExtraFields(m_MaterialEditor);
            GUIHelper.DrawFooter();
        }
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            this.FindProperties(props);

            this.m_MaterialEditor = materialEditor;

            //Style similar to Standard shader
            m_MaterialEditor.SetDefaultGUIWidths();
            m_MaterialEditor.UseDefaultMargins();
            EditorGUIUtility.labelWidth = 0f;

            EditorGUI.BeginChangeCheck();

            //Draw fields
            DoHeader();

            DoMapsArea();
            DoColorArea();

            if (EditorGUI.EndChangeCheck())
            {
                //Apply changes
            }

            GUILayout.Label("Advanced Options", EditorStyles.boldLabel);

            GUIHelper.DrawExtraFields(m_MaterialEditor);

            m_MaterialEditor.ShaderProperty(_UseSpeedTreeWind, new GUIContent("Sample SpeedTree wind"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("If this is a tree created using the SpeedTree Unity Modeler, this toggle will make the shader read the wind information as stored by SpeedTree.", MessageType.None);
            }

            if (showHelp)
            {
                GUIHelper.DrawWindInfo();
            }

            GUIHelper.DrawFooter();
        }
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if (windController == null)
            {
                LocateWindController();
            }
            this.FindProperties(props);

            //Receive
            visualizeVectors = WindController._visualizeVectors;

            this.m_MaterialEditor = materialEditor;

            //Style similar to Standard shader
            m_MaterialEditor.SetDefaultGUIWidths();
            m_MaterialEditor.UseDefaultMargins();
            EditorGUIUtility.labelWidth = 0f;

            EditorGUI.BeginChangeCheck();

            //Draw fields
            DoHeader();

            DoMapsArea();
            DoColorArea();
            DoAnimationArea();

            if (EditorGUI.EndChangeCheck())
            {
                //Send
                WindController.VisualizeVectors(visualizeVectors);
            }

            GUILayout.Label("Advanced Options", EditorStyles.boldLabel);

            GUIHelper.DrawExtraFields(m_MaterialEditor);

            GUIHelper.DrawFooter();
        }
        private void DrawFields()
        {
            DoHeader();

            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(windVectors);
            if (!windVectors.objectReferenceValue)
            {
                EditorGUILayout.HelpBox("Assign a wind vector map for wind to function", MessageType.Error);
                return;
            }

            EditorGUILayout.PropertyField(listenToWindZone, new GUIContent("Listen to Wind Zone"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("When a Wind Zone is assigned, the wind strength and tree trunk weight values are divided by it's \"Main\" parameter value.\n\nThis allows you to use weather systems such as Enviro", MessageType.Info);
            }
            if (listenToWindZone.boolValue)
            {
                EditorGUILayout.PropertyField(windZone, new GUIContent("Wind Zone"));
            }

            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            EditorGUILayout.LabelField("Wind settings", EditorStyles.toolbarButton);
            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(windDirection, new GUIContent("Direction"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("The direction of the wind is equal to the Y-rotation of this object, moving in the postive Z-axis direction.", MessageType.Info);
            }
            EditorGUILayout.PropertyField(windSpeed, new GUIContent("Speed"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("The overall speed of the wind.", MessageType.Info);
            }
            EditorGUILayout.PropertyField(windStrength, new GUIContent("Strength"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("The overall strength of the wind.", MessageType.Info);
            }
            EditorGUILayout.PropertyField(windAmplitude, new GUIContent("Amplitude"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("The overall amplitude of the wind, essentially the size of wind waves.\n\nThe shader have a \"WindAmplitudeMultiplier\" parameter which multiplies this value in the material.", MessageType.Info);
            }

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            EditorGUILayout.LabelField("Tree trunks", EditorStyles.toolbarButton);
            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(trunkWindSpeed, new GUIContent("Speed"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("The speed by which the tree moves.", MessageType.Info);
            }
            EditorGUILayout.PropertyField(trunkWindWeight, new GUIContent("Weight"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("The amount of influence the wind has on a tree.", MessageType.Info);
            }
            EditorGUILayout.PropertyField(trunkWindSwinging, new GUIContent("Swinging"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("A value higher than 0 means the trees will also move against the wind direction.", MessageType.Info);
            }

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            visualizeVectors = EditorGUILayout.Toggle("Visualize wind", visualizeVectors);
            if (showHelp)
            {
                EditorGUILayout.HelpBox("Toggle a visualisation of the wind vectors on all the objects that use FAE shaders featuring wind.\n\nThis allows you to more clearly see the effects of the settings.", MessageType.Info);
            }

            GUIHelper.DrawFooter();
        }
        private void DrawFields()
        {
            DoHeader();

            EditorGUILayout.PropertyField(targetMaterials, true);
            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            EditorGUILayout.LabelField("Coverage", EditorStyles.toolbarButton);
            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(useCoverageShader, new GUIContent("Enable"));

            if (showHelp)
            {
                EditorGUILayout.HelpBox("Covers the objects from the Y-axis", MessageType.Info);
            }

            if (ca.useCoverageShader)
            {
                EditorGUILayout.HelpBox("Currently this feature requires you to have the PigmentMapGenerator script on your terrain", MessageType.Info);

                EditorGUILayout.PropertyField(coverageMap, new GUIContent("Coverage map"));

                if (showHelp)
                {
                    EditorGUILayout.HelpBox("This grayscale map represents the coverage amount on the terrain \n\nThe bottom left of the texture equals the pivot point of the terrain", MessageType.Info);
                }

                EditorGUILayout.PropertyField(coverageColorMap, new GUIContent("Albedo"));
                EditorGUILayout.PropertyField(coverageNormalMap, new GUIContent("Normals"));

                coverageAmount.floatValue = EditorGUILayout.Slider("Amount", coverageAmount.floatValue, 0f, 1f);
                coverageTiling.floatValue = EditorGUILayout.Slider("Tiling", coverageTiling.floatValue, 0f, 20f);
            }

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            EditorGUILayout.LabelField("Object", EditorStyles.toolbarButton);
            EditorGUILayout.Space();

            objectColor.colorValue = EditorGUILayout.ColorField("Color", objectColor.colorValue);
            roughness.floatValue   = EditorGUILayout.Slider("Roughness", roughness.floatValue, 0f, 1f);

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);


            EditorGUILayout.LabelField("Detail", EditorStyles.toolbarButton);
            EditorGUILayout.Space();

            if (showHelp)
            {
                EditorGUILayout.HelpBox("Normal details visible up close", MessageType.Info);
            }


            EditorGUILayout.PropertyField(detailNormalMap, new GUIContent("Detail normal map"));

            detailNormalStrength.floatValue = EditorGUILayout.Slider("Normal strength", detailNormalStrength.floatValue, 0f, 1f);

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            EditorGUILayout.LabelField("Global", EditorStyles.toolbarButton);
            EditorGUILayout.Space();

            if (showHelp)
            {
                EditorGUILayout.HelpBox("A tri-planar projected color map which tiles across all the objects seamlessly", MessageType.Info);
            }

            EditorGUILayout.PropertyField(globalColorMap, new GUIContent("Global color map"));

            globalColor.colorValue  = EditorGUILayout.ColorField("Color", globalColor.colorValue);
            globalTiling.floatValue = EditorGUILayout.Slider("Tiling", globalTiling.floatValue, 0f, 1f);

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            GUIHelper.DrawFooter();
        }
Exemple #11
0
        private void DrawFields()
        {
            DoHeader();

            EditorGUILayout.Space();

            if (!windSubstance.objectReferenceValue)
            {
                EditorGUILayout.HelpBox("The \"FAE_WindVectors\" Substance material could not be located in your project. Was it removed or renamed?", MessageType.Error);

                EditorGUILayout.LabelField("FAE_WindVectors substance");
                EditorGUILayout.PropertyField(windSubstance);
                return;
            }

            visualizeVectors = EditorGUILayout.Toggle("Visualize wind", visualizeVectors);
            if (showHelp)
            {
                EditorGUILayout.HelpBox("Toggle a visualisation of the wind vectors on all the objects that use FAE shaders featuring wind.\n\nThis allows you to more clearly see the effects of the settings.", MessageType.Info);
            }

            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.PropertyField(windVectors);
            EditorGUI.EndDisabledGroup();


            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            EditorGUILayout.LabelField("Wind settings", EditorStyles.toolbarButton);
            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(windDirection, new GUIContent("Direction"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("The direction of the wind is equal to the Y-rotation of this object, moving in the postive Z-axis direction.", MessageType.Info);
            }
            EditorGUILayout.PropertyField(windSpeed, new GUIContent("Speed"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("The overall speed of the wind.", MessageType.Info);
            }
            EditorGUILayout.PropertyField(windStrength, new GUIContent("Strength"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("The overall strength of the wind.", MessageType.Info);
            }
            EditorGUILayout.PropertyField(windAmplitude, new GUIContent("Amplitude"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("The overall amplitude of the wind, essentially the size of wind waves.\n\nThe shader have a \"WindAmplitudeMultiplier\" parameter which multiplies this value in the material.", MessageType.Info);
            }

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            EditorGUILayout.LabelField("Tree trunks", EditorStyles.toolbarButton);
            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(trunkWindSpeed, new GUIContent("Speed"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("The speed by which the tree moves.", MessageType.Info);
            }
            EditorGUILayout.PropertyField(trunkWindWeight, new GUIContent("Weight"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("The amount of influence the wind has on a tree.", MessageType.Info);
            }
            EditorGUILayout.PropertyField(trunkWindSwinging, new GUIContent("Swinging"));
            if (showHelp)
            {
                EditorGUILayout.HelpBox("A value higher than 0 means the trees will also move against the wind direction.", MessageType.Info);
            }

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            GUIHelper.DrawFooter();
        }
Exemple #12
0
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            if (!sb)
            {
                sb = ScriptableObject.CreateInstance <SubstanceBaker>();
            }

            this.m_MaterialEditor = materialEditor;
            this.substance        = m_MaterialEditor.target as ProceduralMaterial;


            this.FindProperties(props);

            //Style similar to Standard shader
            m_MaterialEditor.SetDefaultGUIWidths();
            m_MaterialEditor.UseDefaultMargins();
            EditorGUIUtility.labelWidth = 0f;

            EditorGUI.BeginChangeCheck();

            //Draw fields
            DoHeader();
            DrawFields();

            if (!substance || substance.GetType() != typeof(ProceduralMaterial))
            {
                EditorGUILayout.HelpBox("This is material is not a Substance material\n\nSubstances can be recognized by a small red flame in the icon", MessageType.Error);
            }
            else
            {
                //Retreive the last used folder in the registry
                savedTargetFolder = EditorPrefs.GetString("FAE_S2T_TARGETFOLDER");
                if (targetFolder == null)
                {
                    targetFolder = savedTargetFolder;
                }
                if (targetFolder == null)
                {
                    targetFolder = "Assets/Fantasy Adventure Environment/Terrain/Textures";
                }

                EditorGUILayout.LabelField("Target folder: ", EditorStyles.boldLabel);
                targetFolder = EditorGUILayout.TextField(targetFolder);

                if (targetFolder == null)
                {
                    EditorGUILayout.HelpBox("This field cannot be empty", MessageType.Error);
                }

                if (showHelp)
                {
                    EditorGUILayout.HelpBox("A separate folder will be created with the name of the current Substance material\n\nExample: /" + substance.name + "/texture_name.png", MessageType.Info);
                }

                if (GUILayout.Button("Bake textures") && targetFolder != null)
                {
                    sb.BakeSubstance(substance, targetFolder);
                }
            }

            GUIHelper.DrawFooter();
        }
Exemple #13
0
        // Update is called once per frame
        public override void OnInspectorGUI()
        {
            DoHeader();

            if (pmg.workflow == TerrainUVUtil.Workflow.None)
            {
                EditorGUILayout.HelpBox("Current object is neither a terrain or a mesh!", MessageType.Error);
                return;
            }

            EditorGUI.BeginChangeCheck();

            serializedObject.Update();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Custom pigment map");
            EditorGUILayout.PropertyField(useCustomPigmentMap, new GUIContent(""));
            EditorGUILayout.EndHorizontal();
            if (showHelp)
            {
                EditorGUILayout.HelpBox("This option allows you to assign a custom pigment map, rather than rendering one.", MessageType.Info);
            }

            EditorGUILayout.Space();

            if (useCustomPigmentMap.boolValue)
            {
                EditorGUILayout.PropertyField(inputPigmentMap, new GUIContent("Input"));

                if (showHelp)
                {
                    EditorGUILayout.HelpBox("Grass heightmap should be stored in the alpha channel.", MessageType.Info);
                }


                if (pmg.inputPigmentMap)
                {
                    //Check if input heightmap is readable
                    try
                    {
                        pmg.inputPigmentMap.GetPixel(0, 0);
                    }
                    catch (UnityException e)
                    {
                        if (e.Message.StartsWith("Texture '" + pmg.inputPigmentMap.name + "' is not readable"))
                        {
                            EditorGUILayout.HelpBox("Please enable Read/Write on texture \"" + pmg.inputPigmentMap.name + "\"\n\nWith the texture selected, choose the \"Advanced\" texture type to show this option.", MessageType.Error);
                        }
                    }
                }
            }
            else
            {
                if (pmg.workflow == TerrainUVUtil.Workflow.Terrain && pmg.terrain.terrainData.splatPrototypes.Length == 0)
                {
                    EditorGUILayout.HelpBox("Assign at least one texture to your terrain", MessageType.Error);
                    return;
                }

                if (pmg.workflow == TerrainUVUtil.Workflow.Terrain)
                {
                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                    EditorGUILayout.LabelField("Grass heightmap", EditorStyles.toolbarButton);
                    EditorGUILayout.Space();

                    if (pmg.terrain.terrainData.alphamapResolution >= 2048)
                    {
                        EditorGUILayout.HelpBox("Your splatmap size is 2048px or larger, this can cause severe slowdowns", MessageType.Warning);
                    }

                    //Functionality to be implemented in a later update
                    pmg.heightmapChannel = (PigmentMapGenerator.HeightmapChannel)EditorGUILayout.EnumPopup("Height source material", pmg.heightmapChannel);
                    if (showHelp)
                    {
                        EditorGUILayout.HelpBox("This is the texture whose painted weight will determine the grass height \n\nThe effect can be controlled through the \"Heightmap influence\" parameter on the FAE/Grass shader", MessageType.None);
                    }

                    EditorGUILayout.Space();
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.Space();
                }
                else if (pmg.workflow == TerrainUVUtil.Workflow.Mesh)
                {
                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                    //Field to assign heightmap texture
                    EditorGUILayout.LabelField("Input grass heightmap (optional)", EditorStyles.toolbarButton);
                    EditorGUILayout.Space();

                    pmg.inputHeightmap = EditorGUILayout.ObjectField("Heightmap", pmg.inputHeightmap, typeof(Texture2D), false) as Texture2D;

                    if (showHelp)
                    {
                        EditorGUILayout.HelpBox("This information is used in the \"FAE/Grass\" shader to make the grass shorter where desired", MessageType.Info);
                    }

                    if (pmg.inputHeightmap)
                    {
                        //Check if input heightmap is readable
                        try
                        {
                            pmg.inputHeightmap.GetPixel(0, 0);
                        }
                        catch (UnityException e)
                        {
                            if (e.Message.StartsWith("Texture '" + pmg.inputHeightmap.name + "' is not readable"))
                            {
                                EditorGUILayout.HelpBox("Please enable Read/Write on texture \"" + pmg.inputHeightmap.name + "\"\n\nWith the texture selected, choose the \"Advanced\" texture type to show this option.", MessageType.Error);
                            }
                        }
                    }
                    //Channel dropdown?
                    EditorGUILayout.Space();
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.Space();
                }

                terrainInfo = string.Format("Terrain size: {0}x{1} \nTerrain position: X: {2} Z: {3}", pmg.targetSize.x, pmg.targetSize.z, pmg.targetPosition.x, pmg.targetPosition.z);
                terrainInfo.Replace("\\n", "\n"); //Break lines

                //EditorGUILayout.HelpBox(terrainInfo, MessageType.Info);

                if (pmg.workflow == TerrainUVUtil.Workflow.Mesh)
                {
                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                    EditorGUILayout.LabelField("Texture transformation", EditorStyles.toolbarButton);
                    EditorGUILayout.Space();
                    if (showHelp)
                    {
                        EditorGUILayout.HelpBox("The UV's of your mesh terrain may differ, so these options allow you to compensate for this.", MessageType.Info);
                    }

                    pmg.flipHortizontally = EditorGUILayout.Toggle("Flip horizontally", pmg.flipHortizontally);
                    pmg.flipVertically    = EditorGUILayout.Toggle("Flip vertically", pmg.flipVertically);
                    pmg.textureRotation   = (PigmentMapGenerator.TextureRotation)EditorGUILayout.EnumPopup("Rotation", pmg.textureRotation);

                    EditorGUILayout.Space();
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.Space();
                }

                //Button
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                EditorGUILayout.LabelField("Renderer", EditorStyles.toolbarButton);
                EditorGUILayout.Space();

                pmg.useAlternativeRenderer = EditorGUILayout.ToggleLeft("Use alternative renderer", pmg.useAlternativeRenderer);

                if (showHelp)
                {
                    EditorGUILayout.HelpBox("Some third-party terrain shaders require you to use this, otherwise the result may be black.", MessageType.Info);
                }

                if (pmg.useAlternativeRenderer)
                {
                    pmg.renderLightBrightness = EditorGUILayout.Slider("Brightness adjustment", pmg.renderLightBrightness, 0f, 1f);
                }
                if (pmg.useAlternativeRenderer && showHelp)
                {
                    EditorGUILayout.HelpBox("To compensate for any shader variations on the terrain, you can use this to increase the brightness of the pigment map, in case it turns out too dark/bright.", MessageType.Info);
                }

                EditorGUILayout.Space();
                EditorGUILayout.EndVertical();
            }//else if not custom pigment map

            EditorGUILayout.Space();

            string buttonLabel = (useCustomPigmentMap.boolValue) ? "Assign" : "Generate";

            if (GUILayout.Button(buttonLabel, GUILayout.Height(40f)))
            {
                pmg.Generate();
            }
            EditorGUILayout.Space();

            if (!useCustomPigmentMap.boolValue)
            {
                //Pigment map preview
                EditorGUILayout.BeginHorizontal();
                if (pmg.pigmentMap)
                {
                    EditorGUILayout.LabelField(string.Format("Output pigment map ({0}x{0})", pmg.pigmentMap.height), EditorStyles.boldLabel);
                }
                EditorGUILayout.EndHorizontal();

                if (pmg.pigmentMap)
                {
                    Texture nothing = EditorGUILayout.ObjectField(pmg.pigmentMap, typeof(Texture), false, GUILayout.Width(150f), GUILayout.Height(150f)) as Texture;
                    nothing.name = "Pigmentmap";
                }

                if (pmg.workflow == TerrainUVUtil.Workflow.Terrain)
                {
                    if (pmg.hasTerrainData)
                    {
                        EditorGUILayout.LabelField("The output texture file is stored next to the TerrainData asset", EditorStyles.helpBox);
                    }
                    else
                    {
                        EditorGUILayout.LabelField("The output texture file is stored next to the scene file", EditorStyles.helpBox);
                    }
                }
                else if (pmg.workflow == TerrainUVUtil.Workflow.Mesh)
                {
                    EditorGUILayout.LabelField("The output texture file is stored next to the material file", EditorStyles.helpBox);
                }
            }


            GUIHelper.DrawFooter();

            //Placeholder for realtime updates functionality
            if (GUI.changed)
            {
                Apply();
            }

            serializedObject.ApplyModifiedProperties();

            if (GUI.changed || EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty((PigmentMapGenerator)target);
                EditorUtility.SetDirty(this);
                Apply();
            }
        }
Exemple #14
0
        public override void OnInspectorGUI()
        {
            DoHeader();

            EditorGUI.BeginChangeCheck();

            serializedObject.Update();

            DrawTerrainInfo();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Custom pigment map");
            EditorGUILayout.PropertyField(useCustomPigmentMap, new GUIContent(""));
            EditorGUILayout.EndHorizontal();
            if (showHelp)
            {
                EditorGUILayout.HelpBox("This option allows you to assign a custom pigment map, rather than rendering one.", MessageType.Info);
            }

            EditorGUILayout.Space();

            //Custom pigment map
            if (useCustomPigmentMap.boolValue)
            {
                EditorGUILayout.PropertyField(inputPigmentMap, new GUIContent("Input"));

                if (showHelp)
                {
                    EditorGUILayout.HelpBox("Grass heightmap should be stored in the alpha channel.", MessageType.Info);
                }

                if (pmg.inputPigmentMap)
                {
                    //Check if input heightmap is readable
                    try
                    {
                        pmg.inputPigmentMap.GetPixel(0, 0);
                    }
                    catch (UnityException e)
                    {
                        if (e.Message.StartsWith("Texture '" + pmg.inputPigmentMap.name + "' is not readable"))
                        {
                            EditorGUILayout.HelpBox("Please enable Read/Write on texture \"" + pmg.inputPigmentMap.name + "\"\n\nWith the texture selected, choose the \"Advanced\" texture type to show this option.", MessageType.Error);
                        }
                    }
                }

                EditorGUILayout.Space();
            }

            DoTerrainList();

            EditorGUILayout.Space();

            if (!useCustomPigmentMap.boolValue)
            {
                //Safety check, required for preventing errors when updating from 1.1.2 to 1.2.0
                //if (pmg.terrains == null || pmg.terrains.Length == 0) return;

                //If single terrain without any textures
                if (!isMegaSplat.boolValue)
                {
                    if (!isMultiTerrain.boolValue && pmg.workflow == TerrainUVUtil.Workflow.Terrain && pmg.terrains[0].terrainData.splatPrototypes.Length == 0)
                    {
                        EditorGUILayout.HelpBox("Assign at least one texture to your terrain", MessageType.Error);
                        return;
                    }
                }

                DoHeightMap();

                DoTexTransforms();

                DoRenderer();
            }

            EditorGUILayout.Space();

            //Button
            //If multi terrain, with no objects assigned, don't show Generate button
            if (isMultiTerrain.boolValue && terrainObjects.arraySize == 0)
            {
                EditorGUILayout.HelpBox("Assign at least one terrain object", MessageType.Error);
                terrainObjects.isExpanded = true;
            }

            EditorGUI.BeginDisabledGroup(isMultiTerrain.boolValue && terrainObjects.arraySize == 0);
            string buttonLabel = (useCustomPigmentMap.boolValue) ? "Assign" : "Generate";

            if (GUILayout.Button(buttonLabel, GUILayout.Height(40f)))
            {
                pmg.Generate();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.Space();

            DoPreview();

            GUIHelper.DrawFooter();

            serializedObject.ApplyModifiedProperties();

            if (GUI.changed || EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty((PigmentMapGenerator)target);
                EditorUtility.SetDirty(this);
            }
        }