コード例 #1
0
    public void RunAlgorithmGeneric <T>(
        ref T[,] currentMap,
        T currentTileValue,
        ref Terrain[,] terrainMap,
        ref Improvement[,] improvementMap,
        ref Vector2[,] gradientMap,
        ref System.Random rand,
        Dictionary <Terrain, TerrainMapTile> terrainTileLookup,
        Dictionary <Improvement, ImprovementMapTile> improvementTileLookup,
        MapLayerSettings layerSetting)
    {
        for (int i = 0; i < layerSetting.iterations; i++)
        {
            switch (layerSetting.algorithm)
            {
            case LayerFillAlgorithm.Solid:
                currentMap = LayerMapFunctions.GenerateArray(mapSize, mapSize, currentTileValue);
                break;

            case LayerFillAlgorithm.RandomWalk:
                currentMap = LayerMapFunctions.RandomWalk2D(ref currentMap, ref terrainMap, ref heightMap, rand, currentTileValue,
                                                            layerSetting.radius, false, terrainTileLookup);
                break;

            case LayerFillAlgorithm.Square:
                currentMap = LayerMapFunctions.RandomSquares(ref currentMap, rand, currentTileValue, layerSetting.radius);
                break;

            case LayerFillAlgorithm.PerlinNoise:
                currentMap = LayerMapFunctions.PerlinNoise(ref currentMap, ref terrainMap, ref gradientMap, currentTileValue, rand, layerSetting.PerlinNoiseScale, layerSetting.PerlinNoiseThreshold, layerSetting.MaxGradient, terrainTileLookup);
                break;

            case LayerFillAlgorithm.RandomWalkBlocking:
                currentMap = LayerMapFunctions.RandomWalk2D(ref currentMap, ref terrainMap, ref heightMap, rand,
                                                            currentTileValue, layerSetting.radius, true, terrainTileLookup);
                break;

            case LayerFillAlgorithm.HeightRange:
                LayerMapFunctions.FillHeightRange(ref currentMap, ref heightMap, currentTileValue,
                                                  layerSetting.MinHeight, layerSetting.MaxHeight);
                break;

            case LayerFillAlgorithm.FollowGradient:
                LayerMapFunctions.GadientDescent(ref currentMap, ref heightMap, ref gradientMap, rand, currentTileValue,
                                                 layerSetting.MinStartHeight, layerSetting.MinStopHeight, layerSetting.MaxWidth,
                                                 layerSetting.WidthChangeThrotle);
                break;

            case LayerFillAlgorithm.FollowAlongGradient:
                LayerMapFunctions.FollowAlongGradient(ref currentMap, ref heightMap, ref gradientMap, rand,
                                                      currentTileValue, layerSetting.Width);
                break;

            case LayerFillAlgorithm.AdjacentTiles:
                LayerMapFunctions.AjdacentTiles(ref currentMap, ref heightMap, ref gradientMap, ref terrainMap, ref improvementMap,
                                                rand, currentTileValue, layerSetting.MinThreshold, layerSetting.MaxGradient,
                                                layerSetting.radius, layerSetting.SpawnChance, terrainTileLookup, improvementTileLookup);
                break;

            case LayerFillAlgorithm.Droplets:
                LayerMapFunctions.Droplets(ref currentMap, ref heightMap, ref gradientMap, rand, currentTileValue, layerSetting.PercentCovered);
                break;
            }
        }
    }
コード例 #2
0
    public override void OnInspectorGUI()
    {
        MapLayerSettings mapLayer = (MapLayerSettings)target;

        GUI.changed = false;
        EditorGUILayout.LabelField(mapLayer.name, EditorStyles.boldLabel);

        if (mapLayer.MapTile.Layer == MapLayer.Terrain)
        {
            mapLayer.terrain = (Terrain)EditorGUILayout.EnumPopup(new GUIContent("Terrain type", ""), mapLayer.terrain);
        }
        else
        {
            mapLayer.Improvement = (Improvement)EditorGUILayout.EnumPopup(new GUIContent("Improvement type", ""), mapLayer.Improvement);
        }

        mapLayer.algorithm = (LayerFillAlgorithm)EditorGUILayout.EnumPopup(new GUIContent("Generation Method", "The generation method we want to use to generate the map"), mapLayer.algorithm);

        mapLayer.useLayeredGradients = EditorGUILayout.Toggle("useLayeredGradients", mapLayer.useLayeredGradients);
        mapLayer.randomSeed          = EditorGUILayout.Toggle("Random Seed", mapLayer.randomSeed);
        mapLayer.tile      = EditorGUILayout.ObjectField("", mapLayer.tile, typeof(TileBase), false) as TileBase;
        mapLayer.MapTile   = EditorGUILayout.ObjectField("", mapLayer.MapTile, typeof(MapTileSettings), false) as MapTileSettings;
        mapLayer.IsEnabled = EditorGUILayout.Toggle("Enable", mapLayer.IsEnabled);

        mapLayer.iterations = EditorGUILayout.IntField("Iterations", mapLayer.iterations);
        //Only appear if we have the random seed set to false
        if (!mapLayer.randomSeed)
        {
            mapLayer.seed = EditorGUILayout.FloatField("Seed", mapLayer.seed);
        }

        //Shows different options depending on what algorithm is selected
        switch (mapLayer.algorithm)
        {
        case LayerFillAlgorithm.Solid:
            //No additional Variables
            break;

        case LayerFillAlgorithm.RandomWalk:
        case LayerFillAlgorithm.RandomWalkBlocking:
            mapLayer.iterations = EditorGUILayout.IntField("Iterations", mapLayer.iterations);
            mapLayer.radius     = EditorGUILayout.IntField("Radius", mapLayer.radius);
            break;

        case LayerFillAlgorithm.Square:
            mapLayer.radius = EditorGUILayout.IntField("Size", mapLayer.radius);
            break;

        case LayerFillAlgorithm.PerlinNoise:
            mapLayer.PerlinNoiseScale     = EditorGUILayout.FloatField("Perlin Noise Scale", mapLayer.PerlinNoiseScale);
            mapLayer.PerlinNoiseThreshold = EditorGUILayout.FloatField("Perlin Noise Threshold", mapLayer.PerlinNoiseThreshold);
            mapLayer.MaxGradient          = EditorGUILayout.FloatField("MaxGradient", mapLayer.MaxGradient);
            break;

        case LayerFillAlgorithm.HeightRange:
            mapLayer.MinHeight = EditorGUILayout.FloatField("MinHeight", mapLayer.MinHeight);
            mapLayer.MaxHeight = EditorGUILayout.FloatField("MaxHeight", mapLayer.MaxHeight);
            break;

        case LayerFillAlgorithm.FollowGradient:
            mapLayer.MinStartHeight     = EditorGUILayout.FloatField("minStartHeight", mapLayer.MinStartHeight);
            mapLayer.MinStopHeight      = EditorGUILayout.FloatField("MinStopHeight", mapLayer.MinStopHeight);
            mapLayer.MaxWidth           = EditorGUILayout.FloatField("MaxWidth", mapLayer.MaxWidth);
            mapLayer.WidthChangeThrotle = EditorGUILayout.FloatField("WidthChangeThrotle", mapLayer.WidthChangeThrotle);
            break;

        case LayerFillAlgorithm.FollowAlongGradient:
            mapLayer.Width = EditorGUILayout.FloatField("Width", mapLayer.Width);
            break;

        case LayerFillAlgorithm.AdjacentTiles:
            mapLayer.MinThreshold = EditorGUILayout.FloatField("MinThreshold", mapLayer.MinThreshold);
            mapLayer.MaxGradient  = EditorGUILayout.FloatField("MaxGradient", mapLayer.MaxGradient);
            mapLayer.SpawnChance  = EditorGUILayout.FloatField("SpawnChance", mapLayer.SpawnChance);
            mapLayer.radius       = EditorGUILayout.IntField("Radius", mapLayer.radius);
            break;

        case LayerFillAlgorithm.Droplets:
            mapLayer.PercentCovered = EditorGUILayout.FloatField("PercentCovered", mapLayer.PercentCovered);
            break;
        }

        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
        AssetDatabase.SaveAssets();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(mapLayer);
        }
    }