OptimizedTrailRenderer

author: Nick Gronow (Stick)

Description
Inspired by Yoggy's time-based trail renderer (which you can also find in this wiki), I created this one which offers a couple new features. Like Yoggy's, it adds each segment based on time, and determines when to create each one based on the distance and the angle from the last one added.

Features

 * Set the lifetime of each segment
 * Set any number of colors
 * Set any number of widths
 * Fades out when done
 * Autodestructs when emitting is finished
 * Auto optimizes itself so that it creates as few vertices as necessary over time

One-Time Use
This trail renderer is designed to be a one-time use component. There are several reasons for this, based on the way it is designed for optimization. When emitting is set to false, the trail renderer will stop adding new segments and fade out. The fade out time is set to the segment lifetime.

Optimization
This trail renderer rebuilds the mesh every frame. To compensate for this workload, optimization was made a priority. When the vertex count reaches a certain level (30), max angle and max vertex distance will begin to be increased to keep the vertex count as low as possible. In addition to this, the entire mesh does not need to be rebuilt after emitting has ceased, because it simply fades out over time instead of removing each segment. All of these values can be changed as needed of course based on the scale of your game.