Tag: no 51cto
Unity adds memory when the mesh is updated, and the general method is to use an array to fill in.
Vector3[] vertices = new Vector3[segmentCount * 4]; Vector3[] normals = new Vector3[segmentCount * 4]; Vector4[] tangents = new Vector4[segmentCount * 4]; Color[] colors = new Color[segmentCount * 4]; Vector2[] uvs = new Vector2[segmentCount * 4]; int[] triangles = new int[segmentCount * 6]; mesh.vertices = vertices; mesh.normals = normals; mesh.tangents = tangents; mesh.triangles = triangles; mesh.colors = colors; mesh.uv = uvs;
It's not very convenient to do it every time you request memory.
Later on a post to see
Http://answers.unity3d.com/questions/1102650/avoiding-gc-when-rebuilding-meshuv-and-meshvertice.html
You can actually use list
This will not require you to apply as long as you start applying enough memory.
private List<Vector3> _vertices = new List<Vector3>(1024); private List<Vector3> _normals = new List<Vector3>(1024); private List<Vector4> _tangents = new List<Vector4>(1024); private List<Color> _colors = new List<Color>(1024); private List<Vector2> _uvs = new List<Vector2>(1024); private List<int> _triangles = new List<int>(1024); mesh.SetVertices(_vertices); mesh.SetNormals(_normals); mesh.SetTangents(_tangents); mesh.SetTriangles(_triangles,0); mesh.SetColors(_colors); mesh.SetUVs(0,_uvs);
"Komatsu teaches you to tour the development" "Unity practical skills" when unity mesh update adds memory