Class DrawingData
Helper for drawing Gizmos in a performant way.
This is a replacement for the Unity Gizmos class as that is not very performant when drawing very large amounts of geometry (for example a large grid graph). These gizmos can be persistent, so if the data does not change, the gizmos do not need to be updated.
How to use
Create a Hasher object and hash whatever data you will be using to draw the gizmos Could be for example the positions of the vertices or something. Just as long as if the gizmos should change, then the hash changes as well.
Check if a cached mesh exists for that hash
If not, then create a Builder object and call the drawing methods until you are done and then call Finalize with a reference to a gizmos class and the hash you calculated before.
Call gizmos.Draw with the hash.
When you are done with drawing gizmos for this frame, call gizmos.FinalizeDraw
var a = Vector3.zero;
var b = Vector3.one;
var color = Color.red;
var hasher = DrawingData.Hasher.Create(this);
hasher.Add(a);
hasher.Add(b);
hasher.Add(color);
var gizmos = DrawingManager.instance.gizmos;
if (!gizmos.Draw(hasher)) {
using (var builder = gizmos.GetBuilder(hasher)) {
// Ideally something very complex, not just a single line
builder.Line(a, b, color);
}
}
Inner Types
Public Methods
Get an empty builder for queuing drawing commands.
Call after all Draw commands for the frame have been done to draw everything.
Public Variables
Material to use for lines.
Material to use for surfaces.
Material to use for text.
Private/Protected Members
Returns a new axis aligned bounding box that contains the given bounding box after being transformed by the matrix.
Slightly adjusted scene mode version.
Incremented every time the editor goes from play mode -> edit mode, or edit mode -> play mode.