using UnityEngine; namespace FairyGUI { /// /// /// public class RegularPolygonMesh : IMeshFactory, IHitTest { /// /// /// public Rect? drawRect; /// /// /// public int sides; /// /// /// public float lineWidth; /// /// /// public Color32 lineColor; /// /// /// public Color32? centerColor; /// /// /// public Color32? fillColor; /// /// /// public float[] distances; /// /// /// public float rotation; public RegularPolygonMesh() { sides = 3; lineColor = Color.black; } public void OnPopulateMesh(VertexBuffer vb) { if (distances != null && distances.Length < sides) { Debug.LogError("distances.Length 0) { vb.AddVert(vec, lineColor); xv = Mathf.Cos(angle) * r + centerX; yv = Mathf.Sin(angle) * r + centerY; vb.AddVert(new Vector3(xv, yv, 0), lineColor); } angle += angleDelta; } if (lineWidth > 0) { int tmp = sides * 3; for (int i = 0; i < tmp; i += 3) { if (i != tmp - 3) { vb.AddTriangle(0, i + 1, i + 4); vb.AddTriangle(i + 5, i + 2, i + 3); vb.AddTriangle(i + 3, i + 6, i + 5); } else { vb.AddTriangle(0, i + 1, 1); vb.AddTriangle(2, i + 2, i + 3); vb.AddTriangle(i + 3, 3, 2); } } } else { for (int i = 0; i < sides; i++) vb.AddTriangle(0, i + 1, (i == sides - 1) ? 1 : i + 2); } } public bool HitTest(Rect contentRect, Vector2 point) { if (drawRect != null) return ((Rect)drawRect).Contains(point); else return contentRect.Contains(point); } } }