Class DrawingData

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 = 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

Wrapper for different kinds of commands buffers.

Combines hashes into a single hash value.

Public Methods

Destroys all cached meshes.

Draw (...)

Schedules...

GetBuilder ([hasher], [redrawScope], [renderInGame])

Get an empty builder for queuing drawing commands.

Render (cam, allowGizmos, commandBuffer, allowCameraDefault)

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

Public Variables

frameRedrawScope
Public
lineMaterial

Material to use for lines.

Public
settingsAsset
Public
settingsRef
Public
surfaceMaterial

Material to use for surfaces.

Public
textMaterial

Material to use for text.

Public
version
Public

Private/Protected Members

CeilLog2 (x)
CurrentTime
Private Static
DiscardData (hasher)
GetBuiltInBuilder (renderInGame=…)
GetMesh (desiredVertexCount)
LeakTracking
Internal Static Readonly
MarkerAwaitUserDependencies
Internal Static Readonly
MarkerBuild
Internal Static Readonly
MarkerBuildMeshes
Internal Static Readonly
MarkerCollectMeshes
Internal Static Readonly
MarkerPool
Internal Static Readonly
MarkerRelease
Internal Static Readonly
MarkerSchedule
Internal Static Readonly
MarkerScheduleJobs
Internal Static Readonly
MarkerSortMeshes
Internal Static Readonly
MeshType
Internal
PoolMesh (mesh)
TransformBoundingBox (matrix, bounds)

Returns a new axis aligned bounding box that contains the given bounding box after being transformed by the matrix.

adjustedSceneModeVersion

Slightly adjusted scene mode version.

Private
cachedMeshes
Private
cameraVersions
Private
currentDrawOrderIndex
Private
customMaterialProperties
Private
data
Internal
fontData
Internal
frustrumPlanes
Private
gizmosHandle
Internal
lastTickVersion
Private
lastTickVersion2
Private
lastTimeLargestCachedMeshWasUsed
Private
meshSorter
Private Static Readonly
meshes
Private
persistentRedrawScopes
Private
processedData
Internal
sceneModeVersion

Incremented every time the editor goes from play mode -> edit mode, or edit mode -> play mode.

Internal
stagingCachedMeshes
Private
totalMemoryUsage
Private