using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mapC : MonoBehaviour //地图控制器
{
public int mapSize; //设置地图大小
public float scale; //柏林噪声倍率
public Gradient gradient;
void Start()
{
GameObject map = new GameObject("map");
map.AddComponent<SpriteRenderer>().sprite = CreatSprit();
}
Sprite CreatSprit()
{
Texture2D texture2D = new Texture2D(mapSize, mapSize);
texture2D.SetPixels(CreatColors(mapSize, scale, gradient)); //设置颜色,需要颜色数组
texture2D.Apply();
Rect rect = new Rect(default, new Vector2(texture2D.width, texture2D.height));
return Sprite.Create(texture2D, rect, default);
}
Color[] CreatColors(int mapSize, float scale, Gradient gradient)
{
Color[] colors = new Color[mapSize * mapSize];
float[,] perlinColors = new float[mapSize, mapSize];
for (int y = 0; y < mapSize; y++)
{
for (int x = 0; x < mapSize; x++)
{
//colors[y * mapSize + x] = new Color(
// Mathf.PerlinNoise(x / 100f * scale, y / 100f * scale),
// Mathf.PerlinNoise(x / 100f * scale, y / 100f * scale),
// Mathf.PerlinNoise(x / 100f * scale, y / 100f * scale));
perlinColors[x, y] = Mathf.PerlinNoise(x / 100f * scale, y / 100f * scale);
colors[y * mapSize + x] = gradient.Evaluate(perlinColors[x, y]);
}
}
return colors;
}
}
Unity柏林噪声图代码保存
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。