Exemple #1
0
        private void OnGUI()
        {
            GUILayout.Space(10);

            EditorGUILayout.LabelField("Create " + mapType.ToString() + " Texture", bold);

            EditorGUI.BeginChangeCheck();


            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Width");
            mapWidth = EditorGUILayout.IntField("", mapWidth, GUILayout.MinWidth(0));
            GUILayout.Space(5);
            GUILayout.Label("Height");
            mapHeight = EditorGUILayout.IntField("", mapHeight, GUILayout.MinWidth(0));
            EditorGUILayout.EndHorizontal();

            generateNoisyParameters = EditorGUILayout.ToggleLeft("Automatic Noisy Variance", generateNoisyParameters);
            if (EditorGUI.EndChangeCheck())
            {
                UpdateTex();
            }

            if (generateNoisyParameters)
            {
                switch (mapType)
                {
                case MapType.GrassColor: DrawColorMapGUI(); break;

                case MapType.GrassParameters: DrawParamMapGUI(); break;
                }

                GUILayout.Space(10);

                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();

                GUILayout.Box(new GUIContent(), GUILayout.Width(256), GUILayout.Height(256));
                EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetLastRect(), resultTex);
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
            }


            GUILayout.Space(10);
            GUILayout.Label("Make sure your map resolution is big enough for your terrain!\n" +
                            "Too small of a detail map will mean you won't be able to paint fine details.\n\n" +
                            "The preview is visible live on the grass.",
                            new GUIStyle(EditorStyles.helpBox)
            {
                alignment = TextAnchor.MiddleCenter, padding = new RectOffset(0, 0, 8, 8)
            });
            GUILayout.Space(10);

            if (GUILayout.Button("Create"))
            {
                string fileName = EditorUtility.SaveFilePanelInProject("Choose Save Location", mapType.ToString(), "png", "");
                if (string.IsNullOrEmpty(fileName))
                {
                    return;
                }

                UpdateTex();
                SaveTex(fileName);

                switch (mapType)
                {
                case MapType.GrassColor: grassFlow.colorMap = resultTex; break;

                case MapType.GrassParameters: grassFlow.paramMap = resultTex; break;
                }

                grassFlow.RevertDetailMaps();

                saveComplete = true;

                Close();
            }
        }
    void DrawMapsInspector()
    {
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Detail Maps", bold);

        EditorGUI.BeginChangeCheck();

        EditorGUILayout.BeginHorizontal();
        if (addMapIcon == null)
        {
            _toolIcons = GetToolIcons();
        }

        EditorGUILayout.LabelField(GetContent(() => grassFlow.colorMap), GUILayout.Width(100));
        if (GUILayout.Button(addMapIcon, new GUIStyle(EditorStyles.miniButton)
        {
            fontSize = 13, padding = new RectOffset()
        }, GUILayout.Width(16), GUILayout.Height(16)))
        {
            SaveData();
            GrassFlowMapEditor.Open(grassFlow, GrassFlowMapEditor.MapType.GrassColor);
        }
        Texture2D colorMap = EditorGUILayout.ObjectField(grassFlow.colorMap, typeof(Texture2D), true) as Texture2D;

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField(GetContent(() => grassFlow.paramMap), GUILayout.Width(100));
        if (GUILayout.Button(addMapIcon, new GUIStyle(EditorStyles.miniButton)
        {
            fontSize = 13, padding = new RectOffset()
        }, GUILayout.Width(16), GUILayout.Height(16)))
        {
            SaveData();
            GrassFlowMapEditor.Open(grassFlow, GrassFlowMapEditor.MapType.GrassParameters);
        }
        Texture2D paramMap = EditorGUILayout.ObjectField(grassFlow.paramMap, typeof(Texture2D), true) as Texture2D;

        EditorGUILayout.EndHorizontal();

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(grassFlow, "GrassFlow Set Detail Map");

            grassFlow.colorMap = colorMap;
            grassFlow.paramMap = paramMap;

            if (grassFlow.drawMat)
            {
                if (!colorMap)
                {
                    grassFlow.drawMat.SetTexture("colorMap", null);
                }
                if (!paramMap)
                {
                    grassFlow.drawMat.SetTexture("dhfParamMap", null);
                }
            }

            grassFlow.RevertDetailMaps();
            grassFlow.UpdateShaders();

            Undo.FlushUndoRecordObjects();
        }
    }