Class RetainedGizmos
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 = new RetainedGizmos.Hasher();
hasher.AddHash(a.GetHashCode());
hasher.AddHash(b.GetHashCode());
hasher.AddHash(color.GetHashCode());
if (!gizmos.Draw(hasher)) {
using (var helper = gizmos.GetGizmoHelper(active, hasher)) {
builder.DrawLine(a, b, color);
builder.Finalize(gizmos, hasher);
}
}
Inner Types
Public Methods
Destroys all cached meshes.
Schedules the meshes for the specified hash to be drawn.
Schedules all meshes that were drawn the last frame (last time FinalizeDraw was called) to be drawn again.
Call after all Draw commands for the frame have been done to draw everything.
True if there already is a mesh with the specified hash.
Public Variables
Material to use for the navmesh outline in the editor.
Material to use for the navmesh in the editor.