예제 #1
0
 public TilePaint(Tile tile)
 {
     _tile    = tile;
     BiomeMap = new WeightedBiomeMap(tile, _tile.LodLevel.SplatmapResolution);
 }
        /// <summary>
        /// Displays GUI elements for the "Biomes" tab
        /// </summary>
        public void Biomes()
        {
            const string description = "Create biomes by building a list of constraints that define when a biome should appear.";

            Header("Biomes", description);

            //Blend between biomes amount
            _config.Generator.BiomeBlendAmount =
                EditorGUILayout.Slider("Biome Blend", _config.Generator.BiomeBlendAmount, 0f, 30f);
            _config.Generator.BiomeFalloff =
                EditorGUILayout.FloatField("Falloff", _config.Generator.BiomeFalloff);

            //Display material list editor
            ReorderableListGUI.ListField(_biomeList);

            //Calculate texture preview size
            const float texWidth       = 128;
            float       inspectorWidth = _config.EditorState.InspectorWidth;

            //Previewing
            EditorGUILayout.Space();
            EditorGUI.indentLevel++;
            _config.EditorState.ShowBiomePreview = EditorGUILayout.Foldout(_config.EditorState.ShowBiomePreview, "Show Preview");
            if (_config.EditorState.ShowBiomePreview)
            {
                if (_config.EditorState.BiomePreview != null)
                {
                    var ctr = EditorGUILayout.GetControlRect(false, texWidth);
                    ctr.width = texWidth;
                    ctr.x    += 17;

                    EditorGUI.DrawPreviewTexture(ctr, _config.EditorState.BiomePreview);
                }

                //Zoom slider
                var margin = new GUIStyle {
                    margin = new RectOffset(25, 0, 0, 0)
                };
                GUILayout.BeginHorizontal(margin);

                GUILayout.Label("Zoom", GUILayout.ExpandWidth(false));
                float labelWidth = GUI.skin.label.CalcSize(new GUIContent("Zoom")).x;
                _config.EditorState.BiomePreviewZoom =
                    GUILayout.HorizontalSlider(_config.EditorState.BiomePreviewZoom, 75f, 5f, GUILayout.MaxWidth(texWidth - labelWidth));

                GUILayout.EndHorizontal();

                //Update preview button
                var rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight);
                rect.x    += 17;
                rect.y    += 2;
                rect.width = texWidth;
                if (GUI.Button(rect, "Update Preview"))
                {
                    float startHmSpread  = _config.HeightMapData.Spread;
                    float startTmpSpread = _config.TemperatureMapData.Spread;
                    float startMstSpread = _config.MoistureMapData.Spread;

                    _config.HeightMapData.Spread      /= _config.EditorState.BiomePreviewZoom;
                    _config.TemperatureMapData.Spread /= _config.EditorState.BiomePreviewZoom;
                    _config.MoistureMapData.Spread    /= _config.EditorState.BiomePreviewZoom;

                    TileMesh tm = new TileMesh(null, new LodData.LodLevel(0, 64, 64, 64));
                    tm.CreateHeightmap(new GridPosition());

                    WeightedBiomeMap map = new WeightedBiomeMap(tm, 64);
                    map.CreateMap();
                    _config.EditorState.BiomePreview = map.GetPreviewTexture();

                    _config.HeightMapData.Spread      = startHmSpread;
                    _config.TemperatureMapData.Spread = startTmpSpread;
                    _config.MoistureMapData.Spread    = startMstSpread;
                }
            }

            //Whittaker diagram
            _config.EditorState.ShowWhittakerInfo = EditorGUILayout.Foldout(_config.EditorState.ShowWhittakerInfo, "Whittaker Diagram");
            if (_config.EditorState.ShowWhittakerInfo)
            {
                const string text = "Terra's biomes are based off of Whittaker's biome classification system. " +
                                    "You can read more below.";
                var linkStyle = new GUIStyle(GUI.skin.label)
                {
                    normal  = { textColor = Color.blue },
                    padding = { left = 32 }
                };

                EditorGUI.indentLevel++;

                EditorGUILayout.LabelField(text);

                if (GUILayout.Button("Whittaker Diagram", linkStyle))
                {
                    Application.OpenURL("https://en.wikipedia.org/wiki/File:Climate_influence_on_terrestrial_biome.svg");
                }
                if (GUILayout.Button("Biome Wikipedia", linkStyle))
                {
                    Application.OpenURL("https://en.wikipedia.org/wiki/Biome");
                }

                EditorGUI.indentLevel--;
            }

            EditorGUILayout.Space();
            EditorGUI.indentLevel--;
        }