public void Fill() { int buffer_size = 0; // Cleanup deleted widgets for (int i = mWidgets.Count; i > 0;) { UIWidget widget = mWidgets[--i]; if (widget == null) { mWidgets.RemoveAt(i); } else if (widget.visibleFlag == 1 && widget.gameObject.activeSelf) { buffer_size += widget.bufferSize; } } ResetBuffer(buffer_size); mMtls.Clear(); mTriangleIdx.Clear(); mTriangleIdx.Add(0); Material currMtl = null; // Fill the buffers for the specified material //foreach (UIWidget w in mWidgets) int filled = 0; for (int i = 0; i < mWidgets.Count; i++) { UIWidget w = mWidgets[i]; if (w.visibleFlag == 1 && w.gameObject.activeSelf) { if (currMtl == null || currMtl == w.material) { currMtl = w.material; w.WriteToBuffers(mVerts, mUvs, mCols, filled); filled += w.bufferSize; } else if (currMtl != w.material) { mMtls.Add(currMtl); mTriangleIdx.Add(filled); currMtl = w.material; w.WriteToBuffers(mVerts, mUvs, mCols, filled); filled += w.bufferSize; } } } CleanVertex(filled); if (filled > 0) { mMtls.Add(currMtl); mTriangleIdx.Add(filled); //UIDrawCall dc = GetDrawCall(currMtl, true); //dc.depthPass = depthPass; UIDrawCall dc = GetDrawCall(); if (dc == null) { mDrawCalls.RemoveAt(0); return; } Mesh mesh = dc.FillMesh(mMtls.ToArray(), ChangeMtl); ChangeMtl = false; mesh.vertices = mVerts; mesh.uv = mUvs; mesh.colors = mCols; mesh.subMeshCount = mMtls.Count; int lastidx = 0; int[] mIndices; for (int i = 0; i < mesh.subMeshCount; i++) { int count = mTriangleIdx[i + 1] - mTriangleIdx[i]; int indexCount = (count >> 1) * 3; mIndices = PanelVertexBuffer.GetBuffer(indexCount); int index = 0; for (int j = 0; j < count; j += 4) { mIndices[index++] = j + lastidx; mIndices[index++] = j + lastidx + 1; mIndices[index++] = j + lastidx + 2; mIndices[index++] = j + lastidx + 2; mIndices[index++] = j + lastidx + 3; mIndices[index++] = j + lastidx; } for (int j = index; j < mIndices.Length; j++) { mIndices[j] = 0; } lastidx += count; mesh.SetTriangles(mIndices, i); } //mesh.RecalculateBounds(); } else { //Debug.Log("noting"); if (mDrawCalls.Count > 0 && mDrawCalls[0] != null) { DestroyImmediate(mDrawCalls[0].gameObject); mDrawCalls.RemoveAt(0); } } }