柏林噪声地形图
2023-04-18 15:01:29 时间
public RectTransform redimg;//小地图中的人物红点 public Transform player;//人物 public Image map;//小地图(父级要有个Mash组件) public Texture2D texture; public int w=50; public int h=50; public Color gaocolor = Color.black; public Color dicolor = Color.white; public float max = 10; // Start is called before the first frame update void Start() { texture = new Texture2D(w,h); VertexHelper vh = new VertexHelper(); for (int x = 0; x < w; x++) { for (int z = 0; z < h; z++) { float noise = Mathf.PerlinNoise(x*0.1f, z*0.1f); float y = noise * max; float uvx = (float)x / (float)(w - 1); float uvy = (float)z / (float)(h - 1); Color color = Color.Lerp(dicolor,gaocolor, noise); texture.SetPixel(x, z, color); vh.AddVert(new Vector3(x, y, z), Color.white, new Vector2(uvx, uvy)); if (x != w - 1 && z != h - 1) { vh.AddTriangle(x * h + z, x * h + z + 1, (x + 1) * h + z + 1); vh.AddTriangle(x * h + z, (x + 1) * h + z + 1, (x + 1) * h + z); } } } texture.Apply(); Mesh mesh = new Mesh(); vh.FillMesh(mesh); GetComponent<MeshFilter>().mesh = mesh; GetComponent<MeshCollider>().sharedMesh = mesh; Material material = new Material(Shader.Find("UI/Default")); material.mainTexture = texture; map.material = material; GetComponent<MeshRenderer>().material = material; } // Update is called once per frame void Update() { float pivotX = (player.transform.position.x ) / (float)w; float pivotY = (player.transform.position.z ) / (float)h; map.rectTransform.pivot = new Vector2(pivotX, pivotY); redimg.transform.eulerAngles = Vector3.back * player.transform.eulerAngles.y; }
相关文章
- 量化交易基础 - 009 - 检验 (2)
- linux中redis下载安装部署启动
- 吃透8图1模板,人人可以做架构
- springCloud Alibaba服务的注册与发现之eureka搭建
- Go复合数据类型数组和切片
- Joomla未授权访问漏洞(CVE-2023-23752)
- ChatGPT对于普通人有什么机会和影响?
- what are ESC、BEC and UBEC ?
- 华为云CodeArts Artifact,5大特性守护制品质量与安全
- centos7多网口配置同网段IP解决方案
- LGV 引理
- 【网关开发】9.Openresty 自定义流量分流策略支持灰度(金丝雀)等发布业务场景
- 产品经理
- Centos7单机部署Etcd
- 易基因|DNA甲基化研究的测序数据挖掘思路:干货分享
- MegEngine 使用小技巧:使用 Netron 实现模型可视化
- 网络时间同步设备(时钟同步)产品的功能及技术参数
- 记Cucumber行为驱动测试的简单配置与使用方式
- 产品经理,项目经理,FTO
- 18、实体类对象比对-JSON