Class LineDrawer
Utility class for drawing lines and arrows over the system, for example to visualize structures like spanning trees or to indicate collisions.
One instance of this script is attached to an empty GameObject
in the Simulator Scene. This instance can be accessed as a
singleton object and it maintains a pool of GameObjects that
contain LineRenderers. Note that the class is located in the
AS2.UI
namespace.
Call Clear() to remove all currently displayed lines, use AddLine(Vector2, Vector2, Color, bool, float, float, float) to add lines, and use SetTimer(float) to clear all lines after a specific time.
Inheritance
Namespace: AS2.UI
Assembly: .dll
Syntax
public class LineDrawer : MonoBehaviour
Fields
| Edit this page View SourceactiveLines
Declaration
private List<GameObject> activeLines
Field Value
Type | Description |
---|---|
List<GameObject> |
arrowHeadLength
Declaration
private static float arrowHeadLength
Field Value
Type | Description |
---|---|
float |
arrowHeadWidth
Declaration
private static float arrowHeadWidth
Field Value
Type | Description |
---|---|
float |
arrowLineWidth
Declaration
private static float arrowLineWidth
Field Value
Type | Description |
---|---|
float |
arrowStartOffset
Declaration
private static float arrowStartOffset
Field Value
Type | Description |
---|---|
float |
instance
Declaration
private static LineDrawer instance
Field Value
Type | Description |
---|---|
LineDrawer |
lineWidth
Declaration
private static float lineWidth
Field Value
Type | Description |
---|---|
float |
onTimer
Declaration
private bool onTimer
Field Value
Type | Description |
---|---|
bool |
pool
Declaration
private Stack<GameObject> pool
Field Value
Type | Description |
---|---|
Stack<GameObject> |
timerDuration
Declaration
private float timerDuration
Field Value
Type | Description |
---|---|
float |
timerStart
Declaration
private float timerStart
Field Value
Type | Description |
---|---|
float |
zArrow
Declaration
private static float zArrow
Field Value
Type | Description |
---|---|
float |
zLine
Declaration
private static float zLine
Field Value
Type | Description |
---|---|
float |
Properties
| Edit this page View SourceInstance
The singleton instance of this class.
Declaration
public static LineDrawer Instance { get; }
Property Value
Type | Description |
---|---|
LineDrawer |
Methods
| Edit this page View SourceAddLine(Vector2, Vector2, Color, bool, float, float, float)
Displays a new line to the set of lines that are shown.
Declaration
public void AddLine(Vector2 start, Vector2 end, Color color, bool arrow = false, float width = 1, float arrowWidth = 1, float zOffset = 0)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | start | The grid coordinates of the line's start point. |
Vector2 | end | The grid coordinates of the line's end point. |
Color | color | The color of the line. |
bool | arrow | Whether the line should have an arrow head or not. |
float | width | The width factor of the line. |
float | arrowWidth | The width factor of the arrow head. |
float | zOffset | The z coordinate offset, used to define how multiple lines are layered. Lines with smaller offset will be drawn on top. Arrows are drawn on top of lines by default, with a Z distance of 1. |
Awake()
Declaration
private void Awake()
Clear()
Hides all current lines and resets the timer.
Declaration
public void Clear()
GetLine()
Gets a GameObject with a LineRenderer from the pool, if one is available, or creates a new one otherwise.
Declaration
private GameObject GetLine()
Returns
Type | Description |
---|---|
GameObject | A LineRenderer GameObject that may still be set up for drawing a line. |
InstantiateLine()
Creates a new GameObject with an attached LineRenderer and sets up the LineRenderer's material and number of cap vertices.
Declaration
private GameObject InstantiateLine()
Returns
Type | Description |
---|---|
GameObject | The instantiated GameObject. |
SetTimer(float)
Sets up a timer that clears all lines after the given duration.
Declaration
public void SetTimer(float duration)
Parameters
Type | Name | Description |
---|---|---|
float | duration | The time in seconds after which all lines should be hidden. |
SetupArrowLine(Vector2, Vector2, LineRenderer, float, float, float)
Sets up the given LineRenderer to display a line with an arrow head.
Declaration
private void SetupArrowLine(Vector2 start, Vector2 end, LineRenderer lr, float width = 1, float arrowWidth = 1, float zOffset = 0)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | start | The world coordinates of the line's start point. |
Vector2 | end | The world coordinates of the line's end point. |
LineRenderer | lr | The LineRenderer that should display the line. |
float | width | The width factor of the line. |
float | arrowWidth | The width factor of the arrow head. |
float | zOffset | The Z value to add to the default of all points. |
SetupLine(Vector2, Vector2, LineRenderer, float, float)
Sets up the given LineRenderer to display a basic line.
Declaration
private void SetupLine(Vector2 start, Vector2 end, LineRenderer lr, float width = 1, float zOffset = 0)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | start | The world coordinates of the line's start point. |
Vector2 | end | The world coordinates of the line's end point. |
LineRenderer | lr | The LineRenderer that should display the line. |
float | width | The width factor of the line. |
float | zOffset | The Z value to add to the default of all points. |
Update()
Declaration
private void Update()