Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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);
            }
        }