A line renderer with UV texture mapping and automatic end caps, supporting both absolute and relative sizing modes.
1 Overview
3 Methods
4 Usage
6 See also
The UILineTextureRenderer draws lines between points with proper UV texture mapping, making it ideal for textured lines and trails. The component automatically adds end caps (24 pixels) to the line segments and supports both relative (scaled to RectTransform) and absolute sizing modes. UVs are configured for proper texture wrapping with left/center/right sections.
The properties of the UILineTextureRenderer control are as follows:
| Property | Description |
|---|---|
| UV Rect | UV rectangle used by the texture (default: 0,0,1,1). Defines which portion of the texture to map |
| Line Thickness | Thickness of the drawn line in pixels (default: 2) |
| Use Margins | When enabled, applies margin offsets to the drawing area |
| Margin | Margin offset in pixels (Vector2) applied when Use Margins is enabled |
| Relative Size | When enabled, scales points relative to RectTransform dimensions. When disabled, uses absolute 1:1 scale |
| Points | Array of Vector2 points to draw lines between |
Additional properties available in code:
| Property | Return Type | Description | |
|---|---|---|---|
| uvRect | Rect | Gets or sets the UV rectangle. Setter marks vertices dirty | |
| Points | Vector2[] | Gets or sets the points array. Setter marks all dirty |
The UILineTextureRenderer control does not expose public methods beyond the property setters.
To use the UILineTextureRenderer primitive:
Example code for runtime line creation:
using UnityEngine.UI.Extensions;
public class TexturedLineExample : MonoBehaviour
{
public UILineTextureRenderer lineRenderer;
void Start()
{
// Create a simple line
lineRenderer.Points = new Vector2[]
{
new Vector2(0.1f, 0.1f),
new Vector2(0.5f, 0.8f),
new Vector2(0.9f, 0.2f)
};
lineRenderer.LineThickness = 5f;
lineRenderer.relativeSize = true;
lineRenderer.uvRect = new Rect(0, 0, 1, 1);
}
void DrawPath(Vector2[] pathPoints)
{
lineRenderer.Points = pathPoints;
}
void SetCustomUVMapping()
{
// Use only part of the texture
lineRenderer.uvRect = new Rect(0.25f, 0.25f, 0.5f, 0.5f);
}
}
Note: The component automatically adds 24-pixel caps to the start and end of the line. If fewer than 2 points are provided, it defaults to a simple diagonal line from (0,0) to (1,1).
Video demonstration to be added
Credits: jonbro5556
Based on original LineRender script by jack.sydorenko