``````using UnityEditor;
using UnityEngine;

[RequireComponent(typeof(MeshRenderer), typeof(MeshFilter))]
public class RingMesh : MonoBehaviour
{
//分区
private int segments = 50;
//半径
private int radius = 5;
//内半径
private int interRadius = 3;
private MeshRenderer m_MeshRender;
private MeshFilter m_MeshFilter;

// Use this for initialization
void Start()
{
m_MeshRender = GetComponent<MeshRenderer>();
m_MeshFilter = GetComponent<MeshFilter>();
m_MeshRender.material = CreateMaterial();
m_MeshFilter.mesh = CreateMesh();

MeshFilter[] filter = GetComponentsInChildren<MeshFilter>();
foreach (var item in filter)
{
Debug.Log(item.name);
}
}

private Mesh CreateMesh()
{
Mesh mesh = new Mesh();
//因为要形成闭环，多加两个顶点，方便计算三角形，跟索引0,1的顶点是重合的
int vertexLen = segments * 2 + 2;
//把这个度数改成其他度数，就可以绘制成环形扇面了
int degree = 60;
float angle = degree * Mathf.Deg2Rad;
float curAngle = angle / 2;
float deltaAngle = angle / segments;

//形成圆环，可以绘制一圈等腰梯形。等腰梯形，可以由两个三角形组成。
Vector3[] vertex = new Vector3[vertexLen];
for (int i = 0; i < vertexLen; i += 2)
{
float cos = Mathf.Cos(curAngle);
float sin = Mathf.Sin(curAngle);
vertex[i] = new Vector3(cos * interRadius, 0, sin * interRadius);
vertex[i + 1] = new Vector3(cos * radius, 0, sin * radius);
//为了绘制圆形，当前的角度不断递减
curAngle -= deltaAngle;
}
//填充三角形
//三角形的顶点索引总数，三角形数目 * 3，下面相当于segments * 2 * 3，因为每个segment有两个三角形
int tri_VertexIndexCount = segments * 6;
int[] tri = new int[tri_VertexIndexCount];
for (int i = 0, j = 0; i < tri_VertexIndexCount; i += 6, j += 2)
{
tri[i] = j;
tri[i + 1] = j + 1;
tri[i + 2] = j + 3;
tri[i + 3] = j + 3;
tri[i + 4] = j + 2;
tri[i + 5] = j;
}

//根据顶点位置，设置UV纹理坐标
Vector2[] uv = new Vector2[vertexLen];
for (int i = 0; i < vertexLen; i++)
{
uv[i] = new Vector2(vertex[i].x / radius / 2 + 0.5f, vertex[i].z / radius / 2 + 0.5f);
}

mesh.vertices = vertex;
mesh.triangles = tri;
mesh.uv = uv;
mesh.name = "Sphere";
return mesh;
}

private Material CreateMaterial()
{
Material material = new Material(Shader.Find("Specular"));