Skip to content

Pivot can now be used as reference point when drawing lines #490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions Runtime/Scripts/Primitives/UILineTextureRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class UILineTextureRenderer : UIPrimitiveBase

public float LineThickness = 2;
public bool UseMargins;
public bool UsePivot;
public Vector2 Margin;
public bool relativeSize;

Expand Down Expand Up @@ -72,21 +73,18 @@ protected override void OnPopulateMesh(VertexHelper vh)
sizeX = 1;
sizeY = 1;
}
// build a new set of m_points taking into account the cap sizes.
// would be cool to support corners too, but that might be a bit tough :)

var pointList = new List<Vector2>();
pointList.Add(m_points[0]);
var capPoint = m_points[0] + (m_points[1] - m_points[0]).normalized * capSize;
pointList.Add(capPoint);

// should bail before the last point to add another cap point
for (int i = 1; i < m_points.Length - 1; i++)
for (int i = 0; i < m_points.Length; i++)
{
pointList.Add(m_points[i]);
}
capPoint = m_points[m_points.Length - 1] - (m_points[m_points.Length - 1] - m_points[m_points.Length - 2]).normalized * capSize;
pointList.Add(capPoint);
pointList.Add(m_points[m_points.Length - 1]);

if (UsePivot)
{
offsetX += rectTransform.sizeDelta.x * rectTransform.pivot.x;
offsetY += rectTransform.sizeDelta.y * rectTransform.pivot.y;
}

var Tempm_points = pointList.ToArray();
if (UseMargins)
Expand Down Expand Up @@ -135,14 +133,8 @@ protected override void OnPopulateMesh(VertexHelper vh)
if (i > 1)
vh.AddUIVertexQuad(SetVbo(new[] { prevV1, prevV2, v1, v2 }, uvs));

if (i == 1)
uvs = new[] { uvTopLeft, uvBottomLeft, uvBottomCenter, uvTopCenter };
else if (i == Tempm_points.Length - 1)
uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomRight, uvTopRight };

vh.AddUIVertexQuad(SetVbo(new[] { v1, v2, v3, v4 }, uvs));


prevV1 = v3;
prevV2 = v4;
}
Expand Down