示例#1
0
        public MapData GenerateMap()
        {
            if (GenerateFlatMap)
            {
                return(new MapData(MapWidthX + MapData.NonPlayableBufferSize,
                                   MapLengthZ + MapData.NonPlayableBufferSize));
            }
            else
            {
                if (RandomSeed)
                {
                    Seed = new System.Random(DateTime.UtcNow.Millisecond).Next();
                }

                // Generate Simplex Settings based on parameters set in inspector.
                CurrentSimplexSettings2D =
                    new MapGenerator.SimplexSettings2D(Seed, new System.Numerics.Vector2(Offset.x, Offset.y),
                                                       Scale, Octaves, Persistence, Lacunarity);

                // Generate HeighMap2D from Simplex Settings.
                CurrentHeightMap2D = MapGenerator.GenerateSimplexHeightMap2D(((MapWidthX + (MapData.NonPlayableBufferSize)) * VerticeResolution) + 1,
                                                                             ((MapLengthZ + (MapData.NonPlayableBufferSize)) * VerticeResolution) + 1, CurrentSimplexSettings2D);

                var normalisedNoise = GetNormalisedHeightData(CurrentHeightMap2D);

                return(new MapData(MapWidthX + MapData.NonPlayableBufferSize,
                                   MapLengthZ + MapData.NonPlayableBufferSize, normalisedNoise));
            }

            //  TileMapManager.Instance.ActiveMapData.SetTileTerrainType(TileMapManager.Instance.ActiveMapData.TileMap[26, 27], 5);
        }
示例#2
0
        /// <summary>
        /// Returns noise values of given heightmap normalised to map generation height & world height increments.
        /// </summary>
        /// <param name="heightMap"></param>
        /// <returns></returns>
        public float[,] GetNormalisedHeightData(HeightMap2D heightMap)
        {
            // Create job
            var normaliseJob = new NormaliseHeightJob()
            {
                NoiseData  = new NativeArray <float>(heightMap.HeightData1D, Allocator.TempJob),
                MapHeightY = MapHeightY
            };

            // Schedule job
            jobHandle = normaliseJob.Schedule(heightMap.HeightData1D.Length, 1);
            // Execute job & wait til completion
            jobHandle.Complete();

            //var modifiedFlatData = new float[heightMap.HeightData1D.Length];
            var noise2D = new float[heightMap.HeightData.GetLength(0), heightMap.HeightData.GetLength(1)];

            for (int x = 0, i = 0; x < heightMap.HeightData.GetLength(0); x++)
            {
                for (var z = 0; z < heightMap.HeightData.GetLength(1); z++, i++)
                {
                    noise2D[x, z] = normaliseJob.NoiseData[i];
                }
            }

            //normaliseJob.NoiseData.CopyTo(modifiedFlatData);

            normaliseJob.NoiseData.Dispose();
            return(noise2D);
            //return modifiedFlatData;
        }