Resolves #139
New properties to improve the resolution for a line, which when combined with the LineList creates a dotted line. Supports two modes: dashes based on segments or the entire line.pull/413/head
parent
9ce211c5fc
commit
e373565536
|
@ -131,6 +131,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
pointsToDraw = drawingPoints.ToArray();
|
pointsToDraw = drawingPoints.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImproveResolution != ResolutionMode.None)
|
||||||
|
{
|
||||||
|
pointsToDraw = IncreaseResolution(pointsToDraw);
|
||||||
|
}
|
||||||
|
|
||||||
// scale based on the size of the rect or use absolute, this is switchable
|
// scale based on the size of the rect or use absolute, this is switchable
|
||||||
var sizeX = !relativeSize ? 1 : rectTransform.rect.width;
|
var sizeX = !relativeSize ? 1 : rectTransform.rect.width;
|
||||||
var sizeY = !relativeSize ? 1 : rectTransform.rect.height;
|
var sizeY = !relativeSize ? 1 : rectTransform.rect.height;
|
||||||
|
@ -243,7 +248,13 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
vh.AddUIVertexQuad(segments[i]);
|
vh.AddUIVertexQuad(segments[i]);
|
||||||
}
|
}
|
||||||
}
|
if (vh.currentVertCount > 64000)
|
||||||
|
{
|
||||||
|
Debug.LogError("Max Verticies size is 64000, current mesh vertcies count is [" + vh.currentVertCount + "] - Cannot Draw");
|
||||||
|
vh.Clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private UIVertex[] CreateLineCap(Vector2 start, Vector2 end, SegmentType type)
|
private UIVertex[] CreateLineCap(Vector2 start, Vector2 end, SegmentType type)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
|
public enum ResolutionMode
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
PerSegment,
|
||||||
|
PerLine
|
||||||
|
}
|
||||||
|
|
||||||
public class UIPrimitiveBase : MaskableGraphic, ILayoutElement, ICanvasRaycastFilter
|
public class UIPrimitiveBase : MaskableGraphic, ILayoutElement, ICanvasRaycastFilter
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -17,6 +25,14 @@ namespace UnityEngine.UI.Extensions
|
||||||
internal float m_EventAlphaThreshold = 1;
|
internal float m_EventAlphaThreshold = 1;
|
||||||
public float eventAlphaThreshold { get { return m_EventAlphaThreshold; } set { m_EventAlphaThreshold = value; } }
|
public float eventAlphaThreshold { get { return m_EventAlphaThreshold; } set { m_EventAlphaThreshold = value; } }
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private ResolutionMode m_improveResolution;
|
||||||
|
public ResolutionMode ImproveResolution { get { return m_improveResolution; } set { m_improveResolution = value; SetAllDirty(); } }
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private float m_Resolution;
|
||||||
|
public float Resoloution { get { return m_Resolution; } set { m_Resolution = value; SetAllDirty(); } }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -70,6 +86,52 @@ namespace UnityEngine.UI.Extensions
|
||||||
return vbo;
|
return vbo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Vector2[] IncreaseResolution(Vector2[] input)
|
||||||
|
{
|
||||||
|
var outputList = new List<Vector2>();
|
||||||
|
|
||||||
|
switch (ImproveResolution)
|
||||||
|
{
|
||||||
|
case ResolutionMode.PerLine:
|
||||||
|
float totalDistance = 0, increments = 0;
|
||||||
|
for (int i = 0; i < input.Length - 1; i++)
|
||||||
|
{
|
||||||
|
totalDistance += Vector2.Distance(input[i], input[i + 1]);
|
||||||
|
}
|
||||||
|
increments = totalDistance / m_Resolution;
|
||||||
|
var incrementCount = 0;
|
||||||
|
for (int i = 0; i < input.Length - 1; i++)
|
||||||
|
{
|
||||||
|
var p1 = input[i];
|
||||||
|
outputList.Add(p1);
|
||||||
|
var p2 = input[i + 1];
|
||||||
|
var segmentDistance = Vector2.Distance(p1, p2) / increments;
|
||||||
|
var incrementTime = 1f / segmentDistance;
|
||||||
|
for (int j=0; j < segmentDistance; j++)
|
||||||
|
{
|
||||||
|
outputList.Add(Vector2.Lerp(p1, (Vector2)p2, j * incrementTime));
|
||||||
|
incrementCount++;
|
||||||
|
}
|
||||||
|
outputList.Add(p2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ResolutionMode.PerSegment:
|
||||||
|
for (int i = 0; i < input.Length - 1; i++)
|
||||||
|
{
|
||||||
|
var p1 = input[i];
|
||||||
|
outputList.Add(p1);
|
||||||
|
var p2 = input[i + 1];
|
||||||
|
increments = 1f / m_Resolution;
|
||||||
|
for (Single j = 1; j < m_Resolution; j++)
|
||||||
|
{
|
||||||
|
outputList.Add(Vector2.Lerp(p1, (Vector2)p2, increments * j));
|
||||||
|
}
|
||||||
|
outputList.Add(p2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return outputList.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
#region ILayoutElement Interface
|
#region ILayoutElement Interface
|
||||||
|
|
||||||
|
@ -111,6 +173,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
#region ICanvasRaycastFilter Interface
|
#region ICanvasRaycastFilter Interface
|
||||||
public virtual bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
|
public virtual bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
|
||||||
{
|
{
|
||||||
|
// add test for line check
|
||||||
if (m_EventAlphaThreshold >= 1)
|
if (m_EventAlphaThreshold >= 1)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -129,6 +192,8 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
local = MapCoordinate(local, rect);
|
local = MapCoordinate(local, rect);
|
||||||
|
|
||||||
|
//test local coord with Mesh
|
||||||
|
|
||||||
// Normalize local coordinates.
|
// Normalize local coordinates.
|
||||||
Rect spriteRect = sprite.textureRect;
|
Rect spriteRect = sprite.textureRect;
|
||||||
Vector2 normalized = new Vector2(local.x / spriteRect.width, local.y / spriteRect.height);
|
Vector2 normalized = new Vector2(local.x / spriteRect.width, local.y / spriteRect.height);
|
||||||
|
|
Loading…
Reference in New Issue