Unity Mesh 绘制多边形

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using UnityEngine;
using System.Collections;

public class MeshTest : MonoBehaviour {

private MeshFilter m_MeshFilter;

void Start () {
Mesh mesh = new Mesh();

mesh.vertices = new Vector3[] {
new Vector3(0, 0, 0), // 顶点:0
new Vector3(1, 0, 0), // 顶点:1
new Vector3(1.5f, 1, 0), // 顶点:2
new Vector3(0.6f, 1.5f, 0), // 顶点:3
new Vector3(-0.8f, 1, 0), // 顶点:4
};

// 遵循顺时针三顶点确定一面
mesh.triangles = new int[] {
0, 2, 1, // 面:0, 2, 1
0, 4, 2, // 面:0, 4, 2
4, 3, 2, // 面:4, 3, 2
};


m_MeshFilter = GetComponent<MeshFilter>();
m_MeshFilter.mesh = mesh;
}
}