Class RetainedGizmos

Public

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

Helper for drawing gizmos.

Combines hashes into a single hash value.

Public Methods

ClearCache ()

Destroys all cached meshes.

Public
Draw (hasher)

Schedules the meshes for the specified hash to be drawn.

Public
DrawExisting ()

Schedules all meshes that were drawn the last frame (last time FinalizeDraw was called) to be drawn again.

Public
FinalizeDraw ()

Call after all Draw commands for the frame have been done to draw everything.

Public
GetGizmoHelper (active, hasher)
Public
GetSingleFrameGizmoHelper (active)
Public
HasCachedMesh (hasher)

True if there already is a mesh with the specified hash.

Public

Public Variables

lineMaterial

Material to use for the navmesh outline in the editor.

Public
surfaceMaterial

Material to use for the navmesh in the editor.

Public

Private/Protected Members

GetMesh ()
Private
PoolMesh (mesh)
Private
RemoveUnusedMeshes (meshList)
Private
cachedMeshes
Private
existingHashes
Private
meshes
Private
usedHashes
Private