public void OnPopulateMesh(VertexBuffer vb) { int cnt = elements.Count; if (cnt == 0) { elements[0].OnPopulateMesh(vb); } else { VertexBuffer vb2 = VertexBuffer.Begin(); vb2.contentRect = vb.contentRect; vb2.uvRect = vb.uvRect; vb2.vertexColor = vb.vertexColor; for (int i = 0; i < cnt; i++) { vb2.Clear(); elements[i].OnPopulateMesh(vb2); vb.Append(vb2); } vb2.End(); } }
public void OnPopulateMesh(VertexBuffer vb) { int cnt = elements.Count; if (cnt == 0) { elements[0].OnPopulateMesh(vb); } else { VertexBuffer vb2 = VertexBuffer.Begin(vb); for (int i = 0; i < cnt; i++) { if (activeIndex == -1 || i == activeIndex) { vb2.Clear(); elements[i].OnPopulateMesh(vb2); vb.Append(vb2); } } vb2.End(); } }
public void TintColors(Color[] addtionColors) { if (_meshDirty) { return; } int vertCount = mesh.vertexCount; if (vertCount == 0) { return; } if (addtionColors == null || addtionColors.Length != vertCount) { Tint(); return; } #if !UNITY_5_6_OR_NEWER Color32[] colors = _colors; if (colors == null) { colors = mesh.colors32; } #else VertexBuffer vb = VertexBuffer.Begin(); mesh.GetColors(vb.colors); List <Color32> colors = vb.colors; #endif for (int i = 0; i < vertCount; i++) { Color32 col = _color * addtionColors[i]; col.a = (byte)(_alpha * (hasAlphaBackup ? _alphaBackup[i] : (byte)255)); colors[i] = col; } #if !UNITY_5_6_OR_NEWER mesh.colors32 = colors; #else mesh.SetColors(vb.colors); vb.End(); #endif }
void ChangeAlpha(float value) { _alpha = value; int vertCount = mesh.vertexCount; if (vertCount == 0) { return; } #if !UNITY_5_6_OR_NEWER Color32[] colors = _colors; if (colors == null) { colors = mesh.colors32; } #else VertexBuffer vb = VertexBuffer.Begin(); mesh.GetColors(vb.colors); List <Color32> colors = vb.colors; #endif for (int i = 0; i < vertCount; i++) { Color32 col = colors[i]; col.a = (byte)(_alpha * (hasAlphaBackup ? _alphaBackup[i] : (byte)255)); colors[i] = col; } #if !UNITY_5_6_OR_NEWER mesh.colors32 = colors; #else mesh.SetColors(vb.colors); vb.End(); #endif }
void UpdateMeshNow() { _meshDirty = false; if (_texture == null || _meshFactory == null) { if (mesh.vertexCount > 0) { mesh.Clear(); if (meshModifier != null) { meshModifier(); } } return; } VertexBuffer vb = VertexBuffer.Begin(); vb.contentRect = _contentRect; vb.uvRect = _texture.uvRect; if (_texture != null) { vb.textureSize = new Vector2(_texture.width, _texture.height); } else { vb.textureSize = new Vector2(0, 0); } if (_flip != FlipType.None) { if (_flip == FlipType.Horizontal || _flip == FlipType.Both) { float tmp = vb.uvRect.xMin; vb.uvRect.xMin = vb.uvRect.xMax; vb.uvRect.xMax = tmp; } if (_flip == FlipType.Vertical || _flip == FlipType.Both) { float tmp = vb.uvRect.yMin; vb.uvRect.yMin = vb.uvRect.yMax; vb.uvRect.yMax = tmp; } } vb.vertexColor = _color; _meshFactory.OnPopulateMesh(vb); int vertCount = vb.currentVertCount; if (vertCount == 0) { if (mesh.vertexCount > 0) { mesh.Clear(); if (meshModifier != null) { meshModifier(); } } vb.End(); return; } if (_texture.rotated) { float xMin = _texture.uvRect.xMin; float yMin = _texture.uvRect.yMin; float yMax = _texture.uvRect.yMax; float tmp; for (int i = 0; i < vertCount; i++) { Vector2 vec = vb.uvs[i]; tmp = vec.y; vec.y = yMin + vec.x - xMin; vec.x = xMin + yMax - tmp; vb.uvs[i] = vec; } } hasAlphaBackup = vb._alphaInVertexColor; if (hasAlphaBackup) { if (_alphaBackup == null) { _alphaBackup = new List <byte>(); } else { _alphaBackup.Clear(); } for (int i = 0; i < vertCount; i++) { Color32 col = vb.colors[i]; _alphaBackup.Add(col.a); col.a = (byte)(col.a * _alpha); vb.colors[i] = col; } } else if (_alpha != 1) { for (int i = 0; i < vertCount; i++) { Color32 col = vb.colors[i]; col.a = (byte)(col.a * _alpha); vb.colors[i] = col; } } if (_vertexMatrix != null) { Vector3 camPos = _vertexMatrix.cameraPos; Vector3 center = new Vector3(camPos.x, camPos.y, 0); center -= _vertexMatrix.matrix.MultiplyPoint(center); for (int i = 0; i < vertCount; i++) { Vector3 pt = vb.vertices[i]; pt = _vertexMatrix.matrix.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; vb.vertices[i] = pt; } } mesh.Clear(); #if UNITY_5_2 || UNITY_5_3_OR_NEWER mesh.SetVertices(vb.vertices); if (vb._isArbitraryQuad) { mesh.SetUVs(0, vb.FixUVForArbitraryQuad()); } else { mesh.SetUVs(0, vb.uvs); } mesh.SetColors(vb.colors); mesh.SetTriangles(vb.triangles, 0); if (vb.uvs2.Count == vb.uvs.Count) { mesh.SetUVs(1, vb.uvs2); } #if !UNITY_5_6_OR_NEWER _colors = null; #endif #else Vector3 vertices = new Vector3[vertCount]; Vector2 uv = new Vector2[vertCount]; _colors = new Color32[vertCount]; int triangles = new int[vb.triangles.Count]; vb.vertices.CopyTo(vertices); vb.uvs.CopyTo(uv); vb.colors.CopyTo(_colors); vb.triangles.CopyTo(triangles); mesh.vertices = vertices; mesh.uv = uv; mesh.triangles = triangles; mesh.colors32 = _colors; if (vb.uvs2.Count == uv.Length) { uv = new Vector2[vertCount]; vb.uvs2.CopyTo(uv); mesh.uv2 = uv; } #endif vb.End(); if (meshModifier != null) { meshModifier(); } }
void UpdateMeshNow() { _meshDirty = false; if (_texture == null || _meshFactory == null) { if (_vertices.Count > 0) { _vertices.Clear(); _uv0.Clear(); _colors.Clear(); _triangles.Clear(); if (meshModifier != null) { meshModifier(); } } return; } VertexBuffer vb = VertexBuffer.Begin(); vb.contentRect = _contentRect; vb.uvRect = _texture.uvRect; if (_flip != FlipType.None) { if (_flip == FlipType.Horizontal || _flip == FlipType.Both) { float tmp = vb.uvRect.X; vb.uvRect.X = vb.uvRect.X + vb.uvRect.Width; vb.uvRect.Width = tmp - vb.uvRect.X; } if (_flip == FlipType.Vertical || _flip == FlipType.Both) { float tmp = vb.uvRect.Y; vb.uvRect.Y = vb.uvRect.Y + vb.uvRect.Height; vb.uvRect.Height = tmp - vb.uvRect.Y; } } vb.vertexColor = _color; _meshFactory.OnPopulateMesh(vb); int vertCount = vb.currentVertCount; if (vertCount == 0) { if (_vertices.Count > 0) { _vertices.Clear(); _uv0.Clear(); _colors.Clear(); _triangles.Clear(); if (meshModifier != null) { meshModifier(); } } vb.End(); return; } if (_texture.rotated) { float xMin = _texture.uvRect.X; float yMin = _texture.uvRect.Y; float yMax = _texture.uvRect.Bottom; float tmp; for (int i = 0; i < vertCount; i++) { Vector2 vec = vb.uv0[i]; tmp = vec.Y; vec.Y = yMin + vec.X - xMin; vec.X = xMin + yMax - tmp; vb.uv0[i] = vec; } } _vertices.Clear(); _uv0.Clear(); _colors.Clear(); _triangles.Clear(); _vertices.AddRange(vb.vertices); _uv0.AddRange(vb.uv0); _colors.AddRange(vb.colors); _triangles.AddRange(vb.triangles); vb.End(); if (meshModifier != null) { meshModifier(); } }
void UpdateMeshNow() { _meshDirty = false; if (_texture == null || _meshFactory == null) { if (mesh.vertexCount > 0) { mesh.Clear(); if (meshModifier != null) { meshModifier(); } } return; } VertexBuffer vb = VertexBuffer.Begin(); vb.contentRect = _contentRect; vb.uvRect = _texture.uvRect; vb.vertexColor = _color; _meshFactory.OnPopulateMesh(vb); int vertCount = vb.currentVertCount; if (vertCount == 0) { if (mesh.vertexCount > 0) { mesh.Clear(); if (meshModifier != null) { meshModifier(); } } vb.End(); return; } if (_flip != FlipType.None) { bool h = _flip == FlipType.Horizontal || _flip == FlipType.Both; bool v = _flip == FlipType.Vertical || _flip == FlipType.Both; float xMax = _contentRect.xMax; float yMax = _contentRect.yMax; for (int i = 0; i < vertCount; i++) { Vector3 vec = vb.vertices[i]; if (h) { vec.x = xMax - (vec.x - _contentRect.x); } if (v) { vec.y = -(yMax - (-vec.y - _contentRect.y)); } vb.vertices[i] = vec; } if (!(h && v)) { vb.triangles.Reverse(); } } if (_texture.rotated) { float xMin = _texture.uvRect.xMin; float yMin = _texture.uvRect.yMin; float yMax = _texture.uvRect.yMax; float tmp; for (int i = 0; i < vertCount; i++) { Vector2 vec = vb.uv0[i]; tmp = vec.y; vec.y = yMin + vec.x - xMin; vec.x = xMin + yMax - tmp; vb.uv0[i] = vec; } } hasAlphaBackup = vb._alphaInVertexColor; if (hasAlphaBackup) { if (_alphaBackup == null) { _alphaBackup = new List <byte>(); } else { _alphaBackup.Clear(); } for (int i = 0; i < vertCount; i++) { Color32 col = vb.colors[i]; _alphaBackup.Add(col.a); col.a = (byte)(col.a * _alpha); vb.colors[i] = col; } } else if (_alpha != 1) { for (int i = 0; i < vertCount; i++) { Color32 col = vb.colors[i]; col.a = (byte)(col.a * _alpha); vb.colors[i] = col; } } 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 = vb.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; vb.vertices[i] = pt; } } mesh.Clear(); #if !(UNITY_5_2 || UNITY_5_3_OR_NEWER) if (_vertices == null || _vertices.Length != vertCount) { _vertices = new Vector3[vertCount]; _uv = new Vector2[vertCount]; _colors = new Color32[vertCount]; } vb.vertices.CopyTo(_vertices); vb.uv0.CopyTo(_uv); vb.colors.CopyTo(_colors); if (_triangles == null || _triangles.Length != vb.triangles.Count) { _triangles = new int[vb.triangles.Count]; } vb.triangles.CopyTo(_triangles); mesh.vertices = _vertices; mesh.uv = _uv; mesh.triangles = _triangles; mesh.colors32 = _colors; #else #if !UNITY_5_6_OR_NEWER _colors = null; #endif mesh.SetVertices(vb.vertices); mesh.SetUVs(0, vb.uv0); mesh.SetColors(vb.colors); mesh.SetTriangles(vb.triangles, 0); #endif vb.End(); if (meshModifier != null) { meshModifier(); } }