void LateUpdate() { var meshFilter = transform.GetComponent <MeshFilter>(); var mesh = meshFilter.sharedMesh; mesh.Clear(); var sprites = VisibleSprites(panel.sprites); SortByGUIDepth(sprites); Material[] materials = new Material[sprites.Count]; mesh.subMeshCount = sprites.Count; for (int i = 0; i < sprites.Count; ++i) { var sprite = sprites[i]; Material material; MadList <int> triangles = new MadList <int>(); sprite.DrawOn(ref vertices, ref colors, ref uv, ref triangles, out material); triangles.Trim(); triangleList.Add(triangles); materials[i] = material; } vertices.Trim(); colors.Trim(); uv.Trim(); triangleList.Trim(); mesh.vertices = vertices.Array; mesh.colors32 = colors.Array; mesh.uv = uv.Array; mesh.RecalculateNormals(); for (int i = 0; i < triangleList.Count; ++i) { MadList <int> triangles = triangleList[i]; mesh.SetTriangles(triangles.Array, i); } renderer.sharedMaterials = materials; vertices.Clear(); colors.Clear(); uv.Clear(); triangleList.Clear(); }
void LateUpdate() { if (panel == null) { panel = GetComponent <MadPanel>(); } var visibleSprites = VisibleSprites(panel.sprites); switch (panel.renderMode) { case MadPanel.RenderMode.Legacy: { SortByGUIDepth(visibleSprites); var batchedSprites = Batch(visibleSprites); DrawOnSingleDrawCall(batchedSprites); } break; case MadPanel.RenderMode.DepthBased: { SortByZ(visibleSprites); var batchedSprites = Batch(visibleSprites); DrawOnMultipleDrawCalls(batchedSprites); } break; default: throw new ArgumentOutOfRangeException(); } vertices.Clear(); colors.Clear(); uv.Clear(); triangleList.Clear(); }
void LateUpdate() { if (panel == null) { panel = GetComponent <MadPanel>(); } var mesh = drawCall.mesh; mesh.Clear(); var visibleSprites = VisibleSprites(panel.sprites); SortByGUIDepth(visibleSprites); var batchedSprites = Batch(visibleSprites); Material[] materials = new Material[batchedSprites.Count]; mesh.subMeshCount = batchedSprites.Count; for (int i = 0; i < batchedSprites.Count; ++i) { List <MadSprite> sprites = batchedSprites[i]; MadList <int> triangles; if (!trianglesPool.CanTake()) { trianglesPool.Add(new MadList <int>()); } triangles = trianglesPool.Take(); for (int j = 0; j < sprites.Count; ++j) { var sprite = sprites[j]; Material material; sprite.DrawOn(ref vertices, ref colors, ref uv, ref triangles, out material); materials[i] = material; } triangles.Trim(); triangleList.Add(triangles); } vertices.Trim(); colors.Trim(); uv.Trim(); triangleList.Trim(); mesh.vertices = vertices.Array; mesh.colors32 = colors.Array; mesh.uv = uv.Array; // excluding for metro, because of a bug #if !UNITY_METRO mesh.RecalculateNormals(); #endif for (int i = 0; i < triangleList.Count; ++i) { MadList <int> triangles = triangleList[i]; mesh.SetTriangles(triangles.Array, i); triangles.Clear(); trianglesPool.Release(triangles); } //renderer.sharedMaterials = materials; drawCall.SetMaterials(materials); vertices.Clear(); colors.Clear(); uv.Clear(); triangleList.Clear(); }