利用MeshFilter绘制网格,MeshRenderer获取Texture2D(纹理),增加MeshCollider网格碰撞框
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CreatePanel : MonoBehaviour
{
//添加一个公开的纹理
public Texture2D texture;
void Start()
{
VertexHelper vh = new VertexHelper();
int w = 100;
int h = 100;
for (int x = 0; x <= w; x++)
{
for (int z = 0; z <= h; z++)
{
float y = texture.GetPixel(x, z).grayscale; //获取像素点颜色的灰度值
float uvx = (float)x / w;
float uvz = (float)z / h;
//添加顶点信息
vh.AddVert(new Vector3(x, y, z), Color.white, new Vector2(uvx, uvz));
//添加会指顶点顺序
if (x < w && z < h)
{
vh.AddTriangle(x * (h +