public void UpdateMesh()
{
if (meshModifier != null)
meshModifier();
Vector3[] vertices = this.vertices;
vertCount = vertices.Length;
if (vertexMatrix != null)
{
Matrix4x4 mm = (Matrix4x4)vertexMatrix;
Vector3 camPos = cameraPosition != null ? (Vector3)cameraPosition : Vector3.zero;
Vector3 center = new Vector3(camPos.x, camPos.y, 0);
center -= mm.MultiplyPoint(center);
for (int i = 0; i < vertCount; i++)
{
Vector3 pt = vertices[i];
pt = mm.MultiplyPoint(pt);
pt += center;
Vector3 vec = pt - camPos;
float lambda = -camPos.z / vec.z;
pt.x = camPos.x + lambda * vec.x;
pt.y = camPos.y + lambda * vec.y;
pt.z = 0;
vertices[i] = pt;
}
}
Color32[] colors = this.colors;
for (int i = 0; i < vertCount; i++)
{
Color32 col = colors[i];
if (col.a != 255)
{
if (_alphaBackup == null)
_alphaBackup = new byte[vertCount];
}
col.a = (byte)(col.a * _alpha);
colors[i] = col;
}
if (_alphaBackup != null)
{
if (_alphaBackup.Length < vertCount)
_alphaBackup = new byte[vertCount];
for (int i = 0; i < vertCount; i++)
_alphaBackup[i] = colors[i].a;
}
mesh.Clear();
mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
mesh.colors32 = colors;
meshFilter.mesh = mesh;
if (_stencilEraser != null)
_stencilEraser.meshFilter.mesh = mesh;
}