// Use this for initialization
    void Start()
    {
        ProceduralNoise generator = gameObject.GetComponent <ProceduralNoise>();
        int             minX      = UndestructableTile.getMinx() - PaddingLeft;
        int             maxX      = UndestructableTile.getMaxx() + PaddingRight;
        int             minY      = UndestructableTile.getMiny() - PaddingTop;
        int             maxY      = UndestructableTile.getMaxy() + PaddingBottom;

        int sizeX = Mathf.Abs(minX) + Mathf.Abs(maxX) + 1;
        int sizeY = Mathf.Abs(minY) + Mathf.Abs(maxY) + 1;

        int[,] noise = generator.GenerateNoise(sizeX, sizeY, 0f, 0f, 0.001f, 0.8f);
        for (int i = minX; i < maxX; i++)
        {
            for (int j = minY; j < maxY; j++)
            {
                GameObject Instantiated = Instantiate(WorldTile);
                if (noise[i + Mathf.Abs(minX), j + Mathf.Abs(minY)] == 1)
                {
                    Renderer rendererInstantiated = Instantiated.GetComponent <Renderer>();
                    rendererInstantiated.material = goldMaterial;
                }

                Tile inTile = Instantiated.GetComponent <WorldTile>();
                if (inTile != null)
                {
                    inTile.InitiateTile(CoordinatePair.Init(i, j));
                    StaticWorldObjects.WorldTiles.Add(CoordinatePair.Init(i, j), (WorldTile)inTile);
                }
                Instantiated = Instantiate(StructureTile);
                inTile       = Instantiated.GetComponent <StructureTile>();
                if (inTile != null)
                {
                    inTile.InitiateTile(CoordinatePair.Init(i, j));
                    StaticWorldObjects.WorldStructureTiles.Add(CoordinatePair.Init(i, j), (StructureTile)inTile);
                }
                Instantiated = Instantiate(BackGroundTile);
                inTile       = Instantiated.GetComponent <WorldBackgroundTile>();
                if (inTile != null)
                {
                    inTile.InitiateTile(CoordinatePair.Init(i, j));
                    StaticWorldObjects.WorldBackgroundTiles.Add(CoordinatePair.Init(i, j), (WorldBackgroundTile)inTile);
                }
            }
        }

        this.enabled = false;
    }
Пример #2
0
    /// <summary>
    ///  This function generates the required heightMap for the mesh at the given coordinate
    /// </summary>
    private MapData generateMapData(Vector2 centre)
    {
        //Generate the height map from the noiseData values, we have an extra vertex on each side of the map that isn't rendered so that the mesh's edges,
        //will face the correct orientation and line up with each other
        float[,] noiseMap = ProceduralNoise.generateNoiseMap(mapChunkSize + 2, mapChunkSize + 2, noiseData.noiseScale, noiseData.seed, noiseData.octaves, noiseData.persistance, noiseData.lacunarity, centre + noiseData.offset, noiseData.normalizeMode);

        //If we want to use a falloff map we subtract the given falloff value from the height value for each coordinate
        if (terrainData.useFalloffMap)
        {
            falloffMap = FalloffGenerator.generateFalloffMap(mapChunkSize + 2, falloffCurveA, falloffCurveB);

            //Iterate over all coordinates in the map and take away the falloff value from the height value
            for (int y = 0; y < mapChunkSize + 2; y++)
            {
                for (int x = 0; x < mapChunkSize + 2; x++)
                {
                    //All hights are between [0, 1] so we clamp the values to this range
                    noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - falloffMap[x, y]);
                }
            }
        }
        //return the heightMap stored within the mapData variable
        return(new MapData(noiseMap));
    }