Search Results for

    Show / Hide Table of Contents

    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
    object
    LineDrawer
    Namespace: AS2.UI
    Assembly: .dll
    Syntax
    public class LineDrawer : MonoBehaviour

    Fields

    | Edit this page View Source

    activeLines

    Declaration
    private List<GameObject> activeLines
    Field Value
    Type Description
    List<GameObject>
    | Edit this page View Source

    arrowHeadLength

    Declaration
    private static float arrowHeadLength
    Field Value
    Type Description
    float
    | Edit this page View Source

    arrowHeadWidth

    Declaration
    private static float arrowHeadWidth
    Field Value
    Type Description
    float
    | Edit this page View Source

    arrowLineWidth

    Declaration
    private static float arrowLineWidth
    Field Value
    Type Description
    float
    | Edit this page View Source

    arrowStartOffset

    Declaration
    private static float arrowStartOffset
    Field Value
    Type Description
    float
    | Edit this page View Source

    instance

    Declaration
    private static LineDrawer instance
    Field Value
    Type Description
    LineDrawer
    | Edit this page View Source

    lineWidth

    Declaration
    private static float lineWidth
    Field Value
    Type Description
    float
    | Edit this page View Source

    onTimer

    Declaration
    private bool onTimer
    Field Value
    Type Description
    bool
    | Edit this page View Source

    pool

    Declaration
    private Stack<GameObject> pool
    Field Value
    Type Description
    Stack<GameObject>
    | Edit this page View Source

    timerDuration

    Declaration
    private float timerDuration
    Field Value
    Type Description
    float
    | Edit this page View Source

    timerStart

    Declaration
    private float timerStart
    Field Value
    Type Description
    float
    | Edit this page View Source

    zArrow

    Declaration
    private static float zArrow
    Field Value
    Type Description
    float
    | Edit this page View Source

    zLine

    Declaration
    private static float zLine
    Field Value
    Type Description
    float

    Properties

    | Edit this page View Source

    Instance

    The singleton instance of this class.

    Declaration
    public static LineDrawer Instance { get; }
    Property Value
    Type Description
    LineDrawer

    Methods

    | Edit this page View Source

    AddLine(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.

    | Edit this page View Source

    Awake()

    Declaration
    private void Awake()
    | Edit this page View Source

    Clear()

    Hides all current lines and resets the timer.

    Declaration
    public void Clear()
    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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.

    | Edit this page View Source

    Update()

    Declaration
    private void Update()
    • Edit this page
    • View Source
    In this article
    Back to top AmoebotSim 2.0 Documentation v1.11
    Copyright © 2025 AmoebotSim 2.0 Authors
    Generated by DocFX