Exemplo n.º 1
0
        void CacheTileData(ITerrainSampler terrainSampler, ref MapPixelData mapData)
        {
            // Create array if required
            int dim = MapsFile.WorldMapTileDim + 1;

            if (tileData == null)
            {
                tileData = new int[dim, dim];
            }

            // Populate array with tile metadata
            for (int y = 0; y < dim; y++)
            {
                for (int x = 0; x < dim; x++)
                {
                    // Height sample for ocean and beach tiles
                    float height = TerrainHelper.GetClampedHeight(
                        ref mapData,
                        terrainSampler.HeightmapDimension,
                        (float)x / (float)dim,
                        (float)y / (float)dim) * terrainSampler.MaxTerrainHeight;

                    // Ocean texture
                    if (height <= terrainSampler.OceanElevation)
                    {
                        tileData[x, y] = water;
                        continue;
                    }

                    // Get latitude and longitude of this tile
                    int latitude  = (int)(mapData.mapPixelX * MapsFile.WorldMapTileDim + x);
                    int longitude = (int)(MapsFile.MaxWorldTileCoordZ - mapData.mapPixelY * MapsFile.WorldMapTileDim + y);

                    // Beach texture
                    // Adds a little +/- randomness to threshold so beach line isn't too regular
                    if (height <= terrainSampler.BeachElevation + UnityEngine.Random.Range(-1.5f, 1.5f))
                    {
                        tileData[x, y] = dirt;
                        continue;
                    }

                    // Set texture tile using weighted noise
                    float weight = 0;
                    weight += NoiseWeight(latitude, longitude);
                    // TODO: Add other weights to influence texture tile generation
                    tileData[x, y] = GetWeightedRecord(weight);
                }
            }
        }