20using System.Collections.Generic;
24 [AddComponentMenu(
"UI/Extensions/Primitives/UI Circle")]
27 [Tooltip(
"The Arc Invert property will invert the construction of the Arc.")]
30 [Tooltip(
"The Arc property is a percentage of the entire circumference of the circle.")]
34 [Tooltip(
"The Arc Steps property defines the number of segments that the Arc will be divided into.")]
38 [Tooltip(
"The Arc Rotation property permits adjusting the geometry orientation around the Z axis.")]
42 [Tooltip(
"The Progress property allows the primitive to be used as a progression indicator.")]
45 private float _progress = 0;
52 private List<int> indices =
new List<int>();
53 private List<UIVertex> vertices =
new List<UIVertex>();
54 private Vector2 uvCenter =
new Vector2(0.5f, 0.5f);
59 float Diameter = (rectTransform.rect.width < rectTransform.rect.height ? rectTransform.rect.width : rectTransform.rect.height) -
Padding;
60 float outerDiameter = -rectTransform.pivot.x * Diameter;
61 float innerDiameter = -rectTransform.pivot.x * Diameter +
Thickness;
73 float rad = _inversion * Mathf.Deg2Rad *
ArcRotation;
74 float X = Mathf.Cos(rad);
75 float Y = Mathf.Sin(rad);
77 var vertex = UIVertex.simpleVert;
81 vertex.position =
new Vector2(outerDiameter * X, outerDiameter * Y);
82 vertex.uv0 =
new Vector2(vertex.position.x / Diameter + 0.5f, vertex.position.y / Diameter + 0.5f);
85 var iV =
new Vector2(innerDiameter * X, innerDiameter * Y);
86 if (
Fill) iV = Vector2.zero;
88 vertex.uv0 =
Fill ? uvCenter :
new Vector2(vertex.position.x / Diameter + 0.5f, vertex.position.y / Diameter + 0.5f);
91 for (
int counter = 1; counter <=
ArcSteps; counter++)
93 rad = _inversion * Mathf.Deg2Rad * (counter * stepDegree +
ArcRotation);
98 vertex.position =
new Vector2(outerDiameter * X, outerDiameter * Y);
99 vertex.uv0 =
new Vector2(vertex.position.x / Diameter + 0.5f, vertex.position.y / Diameter + 0.5f);
100 vertices.Add(vertex);
105 vertex.position =
new Vector2(innerDiameter * X, innerDiameter * Y);
106 vertex.uv0 =
new Vector2(vertex.position.x / Diameter + 0.5f, vertex.position.y / Diameter + 0.5f);
107 vertices.Add(vertex);
125 if (counter > _progress)
142 vertex.position = iV;
143 vertex.color = color;
144 vertex.uv0 = uvCenter;
145 vertices.Add(vertex);
147 vh.AddUIVertexStream(vertices, indices);
190 var _color = this.color;
void SetArcRotation(int rotation)
void UpdateBaseAlpha(float value)
void SetPadding(int padding)
void SetThickness(int thickness)
void SetBaseColor(Color color)
void SetArcSteps(int steps)
void SetProgress(float progress)
override void OnPopulateMesh(VertexHelper vh)
void SetProgressColor(Color color)
void UpdateProgressAlpha(float value)
void SetInvertArc(bool invert)
Credit Erdener Gonenc - @PixelEnvision.