Skip to content

Commit

Permalink
border mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mitay-walle committed Jun 10, 2022
1 parent ddc86c4 commit a59dc40
Show file tree
Hide file tree
Showing 4 changed files with 494 additions and 17 deletions.
Binary file added Documentation/border example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 96 additions & 0 deletions Documentation/border example.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions Runtime/UICircleSegmented.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class UICircleSegmented : MaskableGraphic
[Range(1, 360), SerializeField] private int m_SegmentsCount = 360;
[Range(1, 360), SerializeField] private int m_SegmentsPerSpriteCount = 1;
[SerializeField, Range(-10, 10)] private float m_segmentDegreeOffset;
[SerializeField, Range(0,5)] private float m_border;
[SerializeField] private UnityEngine.Gradient m_Gradient = CreateDefaultValidGradient();
[SerializeField] private UnityEngine.Gradient m_Diagonal_Gradient = CreateDefaultValidGradient();
[SerializeField, Range(-360, 360)] private float m_GradientDegreeOffset;
Expand Down Expand Up @@ -188,7 +189,7 @@ protected override void OnPopulateMesh(VertexHelper vh)

if (isOneStepSegment)
{
DrawSegment(currentDegrees, nextDegrees, outer, inner, vh, 0, 1, segmentFill);
DrawSegment(currentDegrees, nextDegrees, outer, inner, vh, 0, 1, m_border>0,segmentFill);
}
else
{
Expand Down Expand Up @@ -221,7 +222,7 @@ protected override void OnPopulateMesh(VertexHelper vh)

float uvStart = (float)j / m_SegmentsPerSpriteCount;
float uvEnd = (float)(j + 1) / m_SegmentsPerSpriteCount;
DrawSegment(degreesStart, degreesEnd, outer, inner, vh, uvStart, uvEnd, subSegmentT);
DrawSegment(degreesStart, degreesEnd, outer, inner, vh, uvStart, uvEnd, m_border>0, subSegmentT);
degreesStart += degreesDelta;
degreesEnd += degreesDelta;
}
Expand All @@ -245,6 +246,26 @@ protected Color GetColor(float degrees, bool isDrawingOuter = false)
return m_Gradient.Evaluate(t) * m_Diagonal_Gradient.Evaluate(t2) * color;
}

protected void DrawSegment(float degreesStart, float degreesEnd, float outer, float inner, VertexHelper vh, float uvStart, float uvEnd,bool wireframe, float t = 1)
{
if (!wireframe)
{
DrawSegment(degreesStart, degreesEnd, outer, inner, vh, uvStart, uvEnd, t);
}
else
{
if (uvStart == 0)
{
DrawSegment(degreesStart, degreesStart+m_border, outer+m_border, inner-m_border, vh, 0, 1, t);
}
if (uvEnd == 1)
{
DrawSegment(degreesEnd-m_border, degreesEnd, outer+m_border, inner-m_border, vh, 0, 1, t);
}
DrawSegment(degreesStart, degreesEnd, outer, outer+m_border, vh, uvStart, uvEnd, t);
DrawSegment(degreesStart, degreesEnd, inner-m_border, inner, vh, uvStart, uvEnd, t);
}
}
protected void DrawSegment(float degreesStart, float degreesEnd, float outer, float inner, VertexHelper vh, float uvStart, float uvEnd, float t = 1)
{
_positionsTemp[0] = DataToPosition(outer, degreesStart);
Expand Down
Loading

0 comments on commit a59dc40

Please sign in to comment.