using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MyImage : MonoBehaviour
{
//MeshRenderer render;
//MeshFilter filter;
//VertexHelper vertex;
//Mesh mesh;
//Color32 color;
//public Texture texture;
// Start is called before the first frame update
//用来渲染Mesh
MeshRenderer render;
//用来添加网格
MeshFilter filter;
//顶点帮助器
VertexHelper vertex;
Color color;
//贴图
public Texture texture;
//网格
Mesh mesh;
int traingleCount = 20;
int radius = 5;
void Start()
{
render = GetComponent<MeshRenderer>();
filter = GetComponent<MeshFilter>();
mesh = new Mesh();
vertex = new VertexHelper();
float perAngle = 2 * Mathf.PI / traingleCount;
vertex.Clear();
vertex.AddVert(new Vector3(0,0,0),Color.white,new Vector2(0,0));
float x = 0, y = 0;
for (int i = 0; i < traingleCount; i++)
{
x = Mathf.Sin(2*Mathf.PI-i*perAngle);
y = Mathf.Cos(2*Mathf.PI-i*perAngle);
color = Color.Lerp(Color.blue,Color.red,(float)i/(traingleCount-1));
vertex.AddVert(new Vector3(x*radius, y*radius, 0),color,new Vector2(x,y));
}
for (int i = 1; i < traingleCount; i++)
{
vertex.AddTriangle(0,i,i+1);
}
vertex.AddTriangle(0,traingleCount,1);
vertex.FillMesh(mesh);
filter.mesh = mesh;
render.material.mainTexture = texture;
//render = GetComponent<MeshRenderer>();
//filter = GetComponent<MeshFilter>();
//mesh = new Mesh();
//vertex = new VertexHelper();
//vertex.Clear();
//vertex.AddVert(new Vector3(0,0,0),Color.red,new Vector2(0,0));
//vertex.AddVert(new Vector3(0,1,0),Color.black,new Vector2(0,1));
//vertex.AddVert(new Vector3(1,1,0),Color.green,new Vector2(1,1));
//vertex.AddVert(new Vector3(1,0,0),Color.yellow,new Vector2(1,0));
//vertex.AddTriangle(0,1,2);
//vertex.AddTriangle(0,2,3);
//vertex.FillMesh(mesh);
//filter.mesh = mesh;
//render.material.mainTexture = texture;
}
// Update is called once per frame
void Update()
{
}
}