UI Line Renderer
Source codeBuild: Unity Package (Download)
Summary
- Goal: Versatile UI line renderer for Unity.
- Languages: C#
- Tech Stack: Unity Engine
- Notable Achievement: Wide range of line types
- Status: Completed
Completed Features
- Straight lines with correct mitre joins.
- Point-to-Point and 'free' bezier lines. [2]
- Configurable line and polygon sizes.
- Polygon generation at line points.
- Per-point transform anchoring. [3]
- Custom inspector property drawer.
Description
I designed this line renderer to supplement my UI within Astraeus after discovering that the existing solutions either performed poorly or were 'hack jobs' that refused to perform the function I needed them for. It's compatible with Unity out of the box, and contains a variety of features and settings.
Challenges
This particular project probably targets one of the areas of math I find more difficult, albeit in 2 dimensions. As a result I've developed some coping strategies to alleviate the difficulty, namely quick iterative debugging with JS (as Unity has no built in line tool to.. debug my line tool) and drawing vector representations in paint.
One of the later challenges I faced was bezier performance. Given that a user may want resolutions up to the hundreds on some particularly long curves, the iterations required become somewhat significant. I deemed GPU porting relatively low priority as it would be a significant rewrite. However, I implemented the next best thing - parallelising the construction of these curves, improving performance by up to 5x on my system. It is interesting to note that the Unity Vector math operator overloads play very poorly with parallel processing. I had to rewrite the math long-form in the parallel code to avoid significant performance impact - approximately 60% worse than serial processing.
Future considerations
In future I may return to port this to a shader, depending on how my line rendering needs evolve. Additionally I'd like to add the ability to configure points and their settings via the mouse in the scene or game view rather than having to manipulate the data manually.