12         static int currentQuads = 0;
    18             foreach (Mesh m 
in meshes)
    30             for (
int i = 0; i < meshes.Length; i++)
    32                 if (null != meshes[i])
    34                     Object.DestroyImmediate (meshes[i]);
    42         public static Mesh[] 
GetMeshes ( 
int totalWidth, 
int totalHeight)
    44             if (HasMeshes () && (currentQuads == (totalWidth * totalHeight))) {
    48             int maxQuads = 65000 / 6;
    49             int totalQuads = totalWidth * totalHeight;
    50             currentQuads = totalQuads;
    52             int meshCount = Mathf.CeilToInt ((1.0f * totalQuads) / (1.0f * maxQuads));
    54             meshes = 
new Mesh [meshCount];
    58             for (i = 0; i < totalQuads; i += maxQuads)
    60                 int quads = Mathf.FloorToInt (Mathf.Clamp ((totalQuads-i), 0, maxQuads));
    62                 meshes[index] = GetMesh (quads, i, totalWidth, totalHeight);
    69         static Mesh 
GetMesh (
int triCount, 
int triOffset, 
int totalWidth, 
int totalHeight)
    71             var mesh = 
new Mesh ();
    72             mesh.hideFlags = HideFlags.DontSave;
    74             var verts = 
new Vector3[triCount * 4];
    75             var uvs = 
new Vector2[triCount * 4];
    76             var uvs2 = 
new Vector2[triCount * 4];
    77             var tris = 
new int[triCount * 6];
    79             for (
int i = 0; i < triCount; i++)
    84                 int vertexWithOffset = triOffset + i;
    86                 float x = Mathf.Floor (vertexWithOffset % totalWidth) / totalWidth;
    87                 float y = Mathf.Floor (vertexWithOffset / totalWidth) / totalHeight;
    89                 Vector3 position = 
new Vector3 (x * 2 - 1, y * 2 - 1, 1.0f);
    91                 verts[i4 + 0] = position;
    92                 verts[i4 + 1] = position;
    93                 verts[i4 + 2] = position;
    94                 verts[i4 + 3] = position;
    96                 uvs[i4 + 0] = 
new Vector2 (0.0f, 0.0f);
    97                 uvs[i4 + 1] = 
new Vector2 (1.0f, 0.0f);
    98                 uvs[i4 + 2] = 
new Vector2 (0.0f, 1.0f);
    99                 uvs[i4 + 3] = 
new Vector2 (1.0f, 1.0f);
   101                 uvs2[i4 + 0] = 
new Vector2 (x, y);
   102                 uvs2[i4 + 1] = 
new Vector2 (x, y);
   103                 uvs2[i4 + 2] = 
new Vector2 (x, y);
   104                 uvs2[i4 + 3] = 
new Vector2 (x, y);
   106                 tris[i6 + 0] = i4 + 0;
   107                 tris[i6 + 1] = i4 + 1;
   108                 tris[i6 + 2] = i4 + 2;
   110                 tris[i6 + 3] = i4 + 1;
   111                 tris[i6 + 4] = i4 + 2;
   112                 tris[i6 + 5] = i4 + 3;
   116             mesh.vertices = verts;
   117             mesh.triangles = tris;
 
static Mesh[] GetMeshes(int totalWidth, int totalHeight)
 
static Mesh GetMesh(int triCount, int triOffset, int totalWidth, int totalHeight)