Class VertexHelper
A utility class that can aid in the generation of meshes for the UI.
Namespace: UnityEngine.UI
Syntax
public class VertexHelper : IDisposable
Remarks
This class implements IDisposable to aid with memory management.
Examples
using UnityEngine;
using UnityEngine.UI;
public class ExampleClass : MonoBehaviour
{
Mesh m;
void Start()
{
Color32 color32 = Color.red;
using (var vh = new VertexHelper())
{
vh.AddVert(new Vector3(0, 0), color32, new Vector2(0f, 0f));
vh.AddVert(new Vector3(0, 100), color32, new Vector2(0f, 1f));
vh.AddVert(new Vector3(100, 100), color32, new Vector2(1f, 1f));
vh.AddVert(new Vector3(100, 0), color32, new Vector2(1f, 0f));
vh.AddTriangle(0, 1, 2);
vh.AddTriangle(2, 3, 0);
vh.FillMesh(m);
}
}
}
Constructors
VertexHelper()
Declaration
public VertexHelper()
VertexHelper(Mesh)
Declaration
public VertexHelper(Mesh m)
Parameters
Type | Name | Description |
---|---|---|
Mesh | m |
Properties
currentIndexCount
Get the number of indices set on the VertexHelper.
Declaration
public int currentIndexCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
currentVertCount
Current number of vertices in the buffer.
Declaration
public int currentVertCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
AddTriangle(Int32, Int32, Int32)
Add a triangle to the buffer.
Declaration
public void AddTriangle(int idx0, int idx1, int idx2)
Parameters
Type | Name | Description |
---|---|---|
Int32 | idx0 | index 0 |
Int32 | idx1 | index 1 |
Int32 | idx2 | index 2 |
AddUIVertexQuad(UIVertex[])
Add a quad to the stream.
Declaration
public void AddUIVertexQuad(UIVertex[] verts)
Parameters
Type | Name | Description |
---|---|---|
UIVertex[] | verts | 4 Vertices representing the quad. |
AddUIVertexStream(List<UIVertex>, List<Int32>)
Add a stream of custom UIVertex and corresponding indices.
Declaration
public void AddUIVertexStream(List<UIVertex> verts, List<int> indices)
Parameters
Type | Name | Description |
---|---|---|
List<UIVertex> | verts | The custom stream of verts to add to the helpers internal data. |
List<Int32> | indices | The custom stream of indices to add to the helpers internal data. |
AddUIVertexTriangleStream(List<UIVertex>)
Add a list of triangles to the stream.
Declaration
public void AddUIVertexTriangleStream(List<UIVertex> verts)
Parameters
Type | Name | Description |
---|---|---|
List<UIVertex> | verts | Vertices to add. Length should be divisible by 3. |
AddVert(UIVertex)
Add a single vertex to the stream.
Declaration
public void AddVert(UIVertex v)
Parameters
Type | Name | Description |
---|---|---|
UIVertex | v | The vertex to add |
AddVert(Vector3, Color32, Vector4)
Add a single vertex to the stream.
Declaration
public void AddVert(Vector3 position, Color32 color, Vector4 uv0)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | Position of the vert |
Color32 | color | Color of the vert |
Vector4 | uv0 | UV of the vert |
AddVert(Vector3, Color32, Vector4, Vector4, Vector3, Vector4)
Add a single vertex to the stream.
Declaration
public void AddVert(Vector3 position, Color32 color, Vector4 uv0, Vector4 uv1, Vector3 normal, Vector4 tangent)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | Position of the vert |
Color32 | color | Color of the vert |
Vector4 | uv0 | UV of the vert |
Vector4 | uv1 | UV1 of the vert |
Vector3 | normal | Normal of the vert. |
Vector4 | tangent | Tangent of the vert |
AddVert(Vector3, Color32, Vector4, Vector4, Vector4, Vector4, Vector3, Vector4)
Add a single vertex to the stream.
Declaration
public void AddVert(Vector3 position, Color32 color, Vector4 uv0, Vector4 uv1, Vector4 uv2, Vector4 uv3, Vector3 normal, Vector4 tangent)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | position | Position of the vert |
Color32 | color | Color of the vert |
Vector4 | uv0 | UV of the vert |
Vector4 | uv1 | UV1 of the vert |
Vector4 | uv2 | UV2 of the vert |
Vector4 | uv3 | UV3 of the vert |
Vector3 | normal | Normal of the vert. |
Vector4 | tangent | Tangent of the vert |
Clear()
Clear all vertices from the stream.
Declaration
public void Clear()
Dispose()
Cleanup allocated memory.
Declaration
public void Dispose()
FillMesh(Mesh)
Fill the given mesh with the stream data.
Declaration
public void FillMesh(Mesh mesh)
Parameters
Type | Name | Description |
---|---|---|
Mesh | mesh |
GetUIVertexStream(List<UIVertex>)
Create a stream of UI vertex (in triangles) from the stream.
Declaration
public void GetUIVertexStream(List<UIVertex> stream)
Parameters
Type | Name | Description |
---|---|---|
List<UIVertex> | stream |
PopulateUIVertex(ref UIVertex, Int32)
Fill a UIVertex with data from index i of the stream.
Declaration
public void PopulateUIVertex(ref UIVertex vertex, int i)
Parameters
Type | Name | Description |
---|---|---|
UIVertex | vertex | Vertex to populate |
Int32 | i | Index to populate. |
SetUIVertex(UIVertex, Int32)
Set a UIVertex at the given index.
Declaration
public void SetUIVertex(UIVertex vertex, int i)
Parameters
Type | Name | Description |
---|---|---|
UIVertex | vertex | The vertex to fill |
Int32 | i | the position in the current list to fill. |