public class BuildingGen : MonoBehaviour
{
public int[] Building;//存储要生成的地块代码
public int[] Probability;//存储概率
public double seed;
public int width = 100;
public int height = 100;
public float noiseScale = 0.1f; //噪声缩放倍数
private int[,] frequencyMap;//存储柏林噪声生成的二维数组
void Start()
{
frequencyMap = new int[width, height];
GeneratePerlinNoise();
//在这里根据需要补一个根据frequencyMap生成地块的代码
}
private void GeneratePerlinNoise()
{
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
float xCoord = (float)x / width * noiseScale;
float yCoord = (float)y / height * noiseScale;
float perlinValue = Mathf.PerlinNoise((float)xCoord + (float)seed, (float)yCoord + (float)seed);
int buildingType = MapPerli
Unity基于种子与地块概率的开放世界2D地图生成
于 2023-10-02 16:53:24 首次发布