UnityEngine.UI.VertexHelper.FillMesh C# (CSharp) Method

FillMesh() public method

Fill the given mesh with the stream data.

public FillMesh ( Mesh mesh ) : void
mesh UnityEngine.Mesh
return void
        public void FillMesh(Mesh mesh)
        {
            mesh.Clear();
            if (this.m_Positions.Count >= 0xfde8)
            {
                throw new ArgumentException("Mesh can not have more than 65000 vertices");
            }
            mesh.SetVertices(this.m_Positions);
            mesh.SetColors(this.m_Colors);
            mesh.SetUVs(0, this.m_Uv0S);
            mesh.SetUVs(1, this.m_Uv1S);
            mesh.SetNormals(this.m_Normals);
            mesh.SetTangents(this.m_Tangents);
            mesh.SetTriangles(this.m_Indices, 0);
            mesh.RecalculateBounds();
        }

Usage Example

Esempio n. 1
0
        private void DoMeshGeneration()
        {
            if (rectTransform != null && rectTransform.rect.width >= 0 && rectTransform.rect.height >= 0)
            {
                OnPopulateMesh(s_VertexHelper);//确定(填充)每一个UI元素Mesh的信息,包括顶点数据、三角形数据、UV数据、顶点色数据
            }
            else
            {
                s_VertexHelper.Clear(); // clear the vertex helper so invalid graphics dont draw.
            }
            var components = ListPool <Component> .Get();

            //获取当前对象是否有IMeshModifier接口
            //Text的描边和阴影都是通过IMeshModifier的ModeifyMesh()实现出来的
            GetComponents(typeof(IMeshModifier), components);

            for (var i = 0; i < components.Count; i++)
            {
                ((IMeshModifier)components[i]).ModifyMesh(s_VertexHelper);
            }

            ListPool <Component> .Release(components);

            s_VertexHelper.FillMesh(workerMesh);
            canvasRenderer.SetMesh(workerMesh);//提交网格信息,开始合并网格
            //SetMesh()方法最终在C++中实现,毕竟由于UI的元素很多,同时参与合并顶点的信息也会很多,在C++中实现效率会更好。
            //UGUI效率会比NGUI要高一些,因为NGUI的“网格Mesh合并”都是在C#中完成的,而UGUI“网格Mesh合并”都是在C++中底层中完成的。
        }
All Usage Examples Of UnityEngine.UI.VertexHelper::FillMesh