Search Unity

Drawing lines in UIDocument

Discussion in 'UI Toolkit' started by unitydungeonmas, Sep 20, 2020.

  1. unitydungeonmas

    unitydungeonmas

    Joined:
    Sep 6, 2020
    Posts:
    37
    Is there a simple way to draw a line between two absolute point inside a VisualElement?
     
  2. liuhuan0924

    liuhuan0924

    Joined:
    Sep 2, 2020
    Posts:
    9
    I usually use bottom border to achieve this effect
     
  3. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    398
    Using borders is one way of getting vertical or horizontal lines. If you want more custom drawing, you can use the generateVisualContent callback to generate a custom mesh using the MeshApi.

    If you're one 2020.1 and above, you can install the com.unity.ui package to see it in action.
    See this post on how to install the package:
    https://forum.unity.com/threads/ui-toolkit-1-0-preview-available.927822/

    Once you have the package installed, in the PackageManager window, select the com.unity.ui package and install the samples. Then, a demo of the mesh api is located in window>UI Toolkit>Rendering>Mesh API
     
    unitydungeonmas likes this.
  4. oobartez

    oobartez

    Joined:
    Oct 12, 2016
    Posts:
    167
    Hi @uMathieu the Mesh API demo seems to be gone. Can we find it anywhere else?
     
  5. niuage

    niuage

    Joined:
    Nov 17, 2019
    Posts:
    123
  6. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    572
    WojtekR likes this.
  7. niuage

    niuage

    Joined:
    Nov 17, 2019
    Posts:
    123
    Excited to use the Vector API in the future, thx :)
     
  8. Salim

    Salim

    Joined:
    Apr 25, 2011
    Posts:
    148
    Hello!
    For those that can't update to Unity 2022 yet, is there code example somewhere for drawing a line using generateVisualContent ?
    Thank you!
     
    Propagant likes this.